Question

Drupal 7 with relevant Modules: Views & Entity Reference

I have a view that simply shows the "Teaser" display type of two different Content Type records, we'll say they are Article and Page.

My Article CT has some simple fields that are shown.

My Page CT has a few fields, but also an Entity Reference field (unlimited entries). The Entity Reference field points to other Article nodes.

My View then, as expected, shows each record's Teaser display and of course when a Page record references another Article record, that Article's teaser is shown as part of the Page teaser.

This is great. The problem is, I do not want to show duplicate Article teasers. That means, if a Page references an Article, I don't want to show that same Article teaser as an individual listing.

Think of it like this, I have these Articles:

  1. Article 1
  2. Article 2
  3. Article 3

And I have these Pages:

  1. Page 4
  2. Page 5
  3. Page 6

Page 4 points -> at Article 1 and Article 2

Page 6 points -> at Article 2

TL;DR

Right now the view would show something like:

  • Article 1
  • Article 2
  • Page 4
    • Article 1
    • Article 2
  • Page 5
  • Page 6
    • Article 2
  • Article 3

What I want is this:

  • Page 4
    • Article 1
    • Article 2
  • Page 5
  • Page 6
    • Article 2
  • Article 3

EDIT: Here's a quick diagram of what I'm trying to do. This is using "Content" instead of "Fields" for the View by the way, since there's unequal fields in the View of the two CTs.

Diagram

Was it helpful?

Solution 2

I ended up knocking this out by making use of the Corresponding Entity Reference module (CER). This creates a 2-way relationship that is sync'd between the parent<->child. Using that, I could simply filter all children which have a parent from the View.

OTHER TIPS

The problem is that the records actually are distinct from a database perspective as there are multiple records generated by different entity references.

The Drupal 8 core issue for this is Views relationships with multi-valued entity reference fields invalidate Distinct query option. There should be usable patches there.

For Drupal 7, use the Views Distinct module as it probably won't be fixed in Views.

From the view page under Advanced section. Click on Other -> Query settings: Settings. Then check Distinct checkbox.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top