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
Comment #2
TrevorBradley CreditAttribution: TrevorBradley commentedOK, 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:
Hey, at least the deltas are accurate now!
If I filter on Delta = 0, I now get:
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.
Comment #3
TrevorBradley CreditAttribution: TrevorBradley commentedComment #4
AnybodyWell 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?
Comment #9
cilefen CreditAttribution: cilefen as a volunteer commentedI am closing this support request because there have been no recent comments.