OK, I'm struggling with this one. I've tackled the problem from a few different directions and can't seem to make it work.

Forgive me if the example I'm using feels a bit obscure. The real example is more complicated, I can elaborate if it's required.

Let me simplify:

I have a Taxonomy. Let's call it foo. Foo has multiple terms, and each term has a weight

I have a Content Type. Let's call it bar. Bar has a multiple field reference to foo, and can have 1 to unlimited values.

Let's say foo has 3 terms with entity IDs of 1, 2, and 3.

Let's say I have a bar content type called "bar_123", with a field_foo value of 1,2,3
I have three other bar nodes: "bar_1", "bar_2", and "bar_3", with single values of 1 , 2, and 3 respectively.

I have a view of taxonomy terms that lists all terms of type foo, which has a relationship to bar. The result would look something like:

EntityID 1
  bar_1
  bar_123
EntityID 2
  bar_2
  bar_123
EntityID 3
  bar_3
  bar_123

Now here's the catch. I want to use foo's weight to display the bar's in a certain order, but I don't want duplicates. In fact, I don't even want to display the entity ID. I want a result of:

bar_1
bar_123
bar_2
bar_3

There are several ways I've attempted to tackle this.

1) If I use aggregation, it works, until I sort on foo's weight. Then all the terms display again (since I'm now sorting on a term that isn't aggregated). I know this is a faulty use of aggregation, but I really don't want to aggregate - I really want to join on only first term in field_foo.
2) If I try to filter on field_foo's delta = 0, even more terms display... the relationship join to bar seems to have all possible delta values, regardless of which element delta field_foo was actually joined against.
3) DISTINCT appears to be failing entirely. (Even if I tell the query it can't rewrite the result)

My core question comes from #2: Why doesn't the joined content type (bar) correctly display its delta? My result looks something like:

EntityID: 1
  bar_1 0
  bar_123 0
  bar_123 1
  bar_123 2
EntityID: 2
  bar_2 0
  bar_123 0
  bar_123 1
  bar_123 2
EntityID: 3
  bar_3 0
  bar_123 0
  bar_123 1
  bar_123 2

Shouldn't it rather look like:

EntityID: 1
  bar_1 0
  bar_123 0
EntityID: 2
  bar_2 0
  bar_123 1
EntityID: 3
  bar_3 0
  bar_123 2

Comments

TrevorBradley created an issue. See original summary.

TrevorBradley’s picture

OK, some progress on this. If I add three fields to the display:

1) foo's Taxonomy Term ID
2) bar's field_foo Entity ID
3) bar's field_foo Delta

If I set #2: field_foo's "Multiple Field Settings" and uncheck "Display all values in the same row", I get a much more sane result:

EntityID: 1
  bar_1 (TermID: 1 field_foo: 1 delta: 0)
  bar_123 (TermID: 1 field_foo: 1 delta 0)
  bar_123 (TermID: 1 field_foo: 2 delta 1)
  bar_123 (TermID: 1 field_foo: 3 delta 2)
EntityID: 2
  bar_2 (TermID: 2 field_foo: 2 delta: 0)
  bar_123 (TermID: 2 field_foo: 1 delta 0)
  bar_123 (TermID: 2 field_foo: 2 delta 1)
  bar_123 (TermID: 2 field_foo: 3 delta 2)
EntityID: 3
  bar_3 (TermID: 3 field_foo: 1 delta: 0)
  bar_123 (TermID: 3 field_foo: 1 delta 0)
  bar_123 (TermID: 3 field_foo: 2 delta 1)
  bar_123 (TermID: 3 field_foo: 3 delta 2)

Hey, at least the deltas are accurate now!

If I filter on Delta = 0, I now get:

EntityID: 1
  bar_1 (TermID: 1 field_foo: 1 delta: 0)
  bar_123 (TermID: 1 field_foo: 1 delta 0)
EntityID: 2
  bar_2 (TermID: 2 field_foo: 2 delta: 0)
  bar_123 (TermID: 2 field_foo: 1 delta 0)
EntityID: 3
  bar_3 (TermID: 3 field_foo: 1 delta: 0)
  bar_123 (TermID: 3 field_foo: 1 delta 0)

Almost there... now I just need a filter that compares the term ID with field_foo..

Sadly, Drupal 7 had a field comparison filter, but Drupal 8 views doesn't seem to have this.

It still would be ideal to filter on the delta directly in the relationship.

TrevorBradley’s picture

Title: Views Relationship: How to force Delta = 0 on target? » Views Relationship: Set delta for "Taxonomy term referenced from field"
Anybody’s picture

Well I think these two issues could be related? Would you mind to have a look? Perhaps we should then close this as duplicate and proceed there?

#844910: Change behavior of add_orderby #3020585: Isn't this a core issue?

Version: 8.2.7 » 8.2.x-dev

Core issues are now filed against the dev versions where changes will be made. Document the specific release you are using in your issue comment. More information about choosing a version.

Version: 8.2.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Branches prior to 8.8.x are not supported, and Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev
cilefen’s picture

Status: Active » Closed (outdated)

I am closing this support request because there have been no recent comments.