views:

20

answers:

1

Hi,

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:

A has a nodereference of ID:1, B has a Node ID:1, I want to show fields from C where nodereference of ID is also 1. How is this possible? I can't figure out the mapping.

Can someone help me out please ?

+1  A: 

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
Sid NoParrots
@Nealv: Instead of Node Referrer (that i've used) you can also look at http://drupal.org/project/reverse_node_reference (it requires MySQL 5.1). See http://drupal.org/node/798786 for differences with Node Referrer. Essentially the main advantage is that you would not need to create a fresh field in content type B. You will just get a reverse node reference in views relationships. It might be a little bit more "elegant" in that respect. But both methods will work.
Sid NoParrots

related questions