1

I have a content type "Lunch" containing a paragraph type field named "Ingredients". This is a multiple values field which store a prapgraph type named "Ingedients" => Taxonomy term + Quantity

LUNCH

|- Ingredient1 (Term1 reference + quantity1)

|- Ingredient2 (Term2 reference + quantity2)

I have created a view displaying the tiles of my 3 encoded lunches. Until here, everything is fine.

Now, I would like to add an exposed filter to get all lunches congtaining a specific ingredient. For this I have added a relationship on the ingredient field:

Paragraph referenced from field_ingredients

Doing this is fine, because now, I can add an exposed filter using this relationship

AND

Doing this is bad, because as soon as I have added this relationship the number of rows in my view has been multiplcated by the number of ingredients... even if I check distinct in the SQL parameters

Any hint to solve this issue?

EDIT TO ADD: I could solve this by removing the duplicates in hook_views_pre_render but is it really the best thing to do?

REAL SOLUTION BASED ON prkos ANSWER:

1-In the advance>Other section I have enabled the aggregation

2-I have added my Ingredient field in the field section (exclude from display)

=>This is the taxonomy reference field of my Paragraphs field named "Ingedients". In other words, I have a paragraph type with 2 fields (Ingredient and quantity) and I selected "Ingredient". Do not select the paragraph itself.

3-In the aggregation parameter of this added field, I selected ID of the entity

  • well you can remove them with "hook_views_pre_render" . but you are right thats not that great, have you "required" this relationship ? can you go to "admin/structure/views/settings" and tick "Show SQL query" and "Show other queries run during render during live preview", then update the question with output thanks – Taggart Jensen Jun 14 at 4:00
1

Adding Relationships often causes duplicate rows in the results.

You can "remove" the duplicates using the Aggregation in Views (enable it under Advanced).

Then adjust the Aggregation settings for some Fields, specifically the Group column option. You may need to change it from Value to Entity ID or vice versa. The exact combination of settings depends on your particular case, I haven't tried it with Paragraphs.

When duplicates are introduced through Taxonomy reference field that is using a Relationship then all those Taxonomy fields need to have the Entity ID and not the Value.

If the field is a direct Entity Reference field and isn't using a Relatinship then again it needs to be Entity ID instead of, in this case, target_id.

Be careful with Sort criteria when using Aggregation, some of them can mess up the Aggregation. It's best to remove all Sort criteria while adjusting the Aggreation, then when you have it working add them and test that everything is still working as expected.

Some modules offer more advanced Aggregation settings, try looking into that if you need to, for example: Views Aggregator Plus,

  • This is exactly what I was looking for. I will add a small description on how I could achieve this with nyour help. – Baud Jun 15 at 9:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.