drupaldrupal-6drupal-viewsdrupal-views-relationship

Drupal Views relationship


In Drupal I have 3 content types (A, B, C) see link. A and C contain a node reference to B.

Now I have a view which queries fields from A from an argument. I want to also show fields from C trough the relationschip with B, so:

Can someone help me out please?


Solution

  • Currently you can easily go from A to B via the Node Reference but since the link is from C to B you cannot get the link to C -- this is the current problem.

    In short, you can solve the problem by using the module Node Referrer (see http://drupal.org/node/431308 for what it does). Essentially it creates a read only field that tells you all the nodes pointing from C to B (i.e. a sort of reverse node reference is created for each node reference).

    So lets say we have the following Node Reference fields

    1. In content type A we have the node reference field called a_to_b_link
    2. In content type C we have the node reference field called c_to_b_link
    3. In content type B we have the Node Referrer field that tracks all the links in the Node Reference c_to_b_link

    Creating the corresponding view is a little bit more involved.

    1. First add a filter for Node: Type = A
    2. Add a relationship a_to_b_link. Make sure the you tick the checkbox Require this relationship
    3. Add another relationship from the Node group called Node: Referrers. Also make sure in the settings for the relationship you should choose the a_to_b_link in the Relationship drop down. In other words you are making a relationship that uses a pre-existing relationship (similar in concept to a pointer to a pointer in C++) Make sure the you tick the checkbox Require this relationship. This relationship by default is named Referencing Nodes by Drupal.
    4. Now add whatever fields you want from content type A as you would do normally in the view.
    5. When you want to add fields from content type C make sure you select the relationship Referencing Nodes