0

I have two node types, which I'll call A and B. Type A is a fairly straightforward content type, the only thing special is that it has a field (field_appearances) that references B nodes (tag-style, so each A may have one or more B tagged).

I am using Views to create a nice listing of all my B nodes, and I would like to have each B in this view list the A nodes that are referencing it (basically, so that users can easily see a list of A's that reference that particular B).

Effectively, this should look something like this:

B.1

  • Used in: A.1, A.2, A.3

B.2

  • Used in: A.2, A.4

What I've tried

First, I tried setting a relationship Content using field_appearances, then added a Title field to the view that used that relationship. This created a row for each B+A like so:

B.1

  • Used in: A.1

B.1

  • Used in: A.2

B.1

  • Used in: A.3

(...and so on for each B)

Next, I enabled aggregation and tried using various setups to get this right. The closest I got was setting the (referenced) Title field to aggregate on COUNT, which got me the following:

B.1

  • Used in: 3

B.2

  • Used in: 2

Any suggestions? I tried dinking around with Contextual filters but didn't get anything close to being right.

1 Answer 1

0

The Relationships and Aggregation features are fairly limited as they directly work on the database query, so you can only aggregate using very simple functions like COUNT, AVG, MAX etc.

What you are trying to do (load multiple related values for each row, and render them together) can be done with a sub-view, for example with this module: https://www.drupal.org/project/views_field_view

That would allow you to create a separate view ("Nodes referencing a particular node") with a contextual filter, then add this view as a field to the main view. It slightly impacts performance, as each row in the parent view executes a new sub-view, but should be okay with caching.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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