Create a view on a node reference field
Last modified: June 18, 2009 - 19:29
NOTE: I have requested that this be added to Advanced Help within views. See http://drupal.org/node/495600
You can use views 2 to query the nodes which are referred from a certain cck's node reference field. This can be used for example to sort the referred nodes according to their title.
In this example we will reference Artist to his/her Songs.
- Content type 'Song'
-
Create a content type 'Song'
- Add several Song nodes
- Content type 'Artist'
- Create a content type 'Artist' with a node reference field referencing the Song content type. (You can set the 'Number of values' to more than 1). Let's call the field field_reference_song
- Add an Artist node and in the node reference field add all the Song nodes
- Views
- Add a view with view type 'node'.
- In Relationships section: select the node reference field and enable 'Require this relationship'
- In Arguments section: select 'Node:nid' - this will be used to enter the Artist's node id
- In Fields section: select 'Node:Title'. In the Relationships select list select your node reference field
- In Sort criteria section: select Node:title.
Your view is ready. In the Live preview enter your Artist's node id and you should get all the songs referred from that node sorted in alphabetical order.

I've haven't tried this
I've haven't tried this exercise yet. However, i can see it as being using for a periodical with multiple issues.
Thank you for taking the time to figure this out and write it up.
Tom
Links to referred nodes?
If I get this right, we create a view to get a single artist node and then display all referred-to songs. I think this should be added to the text as I had a hard time to understand the idea...
Now I have the view I wanted but how can I link the song titles to their nodes? All I get is links to the artist node which is not relevant here. Seems to be a problem because we don't really have a view of songs.
#380082: Links to referred nodes
To have a view (i.e. list) of
To have a view (i.e. list) of the songs of each artist, you just need to create a link to www.example.com/view_name/nid where view_name is the name your path (on the page Display).
You could easily add this link on your node-yournodetype.tpl.php page or by adding a Link CCK field.
Has anybody used this
Has anybody used this tutorial successfully. If so would it be possible for you to post your Views export. Thank you.
Using this example can you
Using this example can you create a View that would show all the Artist from a song page?
I think the idea is more like
I think the idea is more like "list all the songs of that artist", but yes, you can do both.
Excellent, simple, nice
Thanks, subscribing
Thanks.
This was helpful.
We used this to get a custom node listing as a block on a noderef page.
So we have this node types Series and Lectures. Series noderef to many Lectures.
On any given /series/* page, you'll see the Series title, description, and noderef list of Lectures.
To use the same teaser display we set up for Lectures on the home page, we created a view following the steps above, up until 8. Instead of Fields, we used Node.
Then we had to specify the Argument -> Node: Id with a default argument. Clicking on that, the last radio button is "Provide default argument", then select Node ID from URL as your "Default argument type." Then we created a block view.
Last, we moved the block to the main content region and limited to /series/* pages. I also had to make a blank tpl so that the default noderef list wouldn't render. This required the unfortunate name of content-field-field_noderef-series.tpl.php.
I never got this to work.
I never got this to work. Since I am new in Drupal, it might be just me. However, this worked for me just fine: http://drupalmodules.com/module/node-reference-views . Hope it helps!
Thanks a lot...
... for sharing this tip. This allows me to achieve successfully a long search! I was trying for a long time to filter dynamically some child "B" content-types according to a common nodereference which is also the title of a parent "A" content type. The final aim was to attach dynamically below a A content type a view list with all B content types related to A (and only them), using Views Insert.
I was mainly trying to set an argument based on the nodereference field located on B content types. I was testing some php code to do that, without success. And eventually you gave me the idea to use the nodereference as a relationship, and the node title as argument. I'll sleep far better tonight. Thanks again.
Possible with Content Multigroup ?
I'm using 2 content types corresponding to persons (Content Profile) and groups. The "person" type should reference some "groups" with the person's position and date (using a Content Multigroup to allow membership to multiple groups).
Is it possible to display on each group page, the list of its members (possibly filtered by function/date)?