views:

125

answers:

2

I'm trying to set up a relational View but not sure how to do it.

Here's an example of what I'm going for using the node types Artist and Song.

Artist               Song                    Length
Bob Dylan           Like a Rolling Stone     2:00
Bruce Springsteen   Atlantic City            4:00
Burce Springsteen   Born to Run              5:24
Van Morrison         Domino                   3:22
Van Morrison         Brown Eyed Girl          4:30

Assuming I have an Artist node type that has a node reference to Song (set to unlimited) and a Song data type with an additional field for length, how would I go about configuring the view to output this view?

Thanks! Ian

+1  A: 

This is basically the reference use case for Views 'Relationships' -- they're a way of explicitly spelling out joins to pull in different sets of nodes in the same view.

If I were building it, I'd create a Song content type that has a single node reference to Artist. Then I'd build a View of Songs that includes the 'Song Title' and 'Song Length' fields. Then I'd add a relationship for the 'Artist' node reference field. Once you've added a relationship like that, you can add a SECOND 'Title' field to the view, and specify that it should be taken from the artist node rather than the song node.

Eaton
Thanks @Eaton. Unfortunately the content types were already built the other way around with a ton of data already entered, so I wasn't able to go with your method. Seems like it'd work great when starting from scratch though!If you're curious how I did it, check out my answer below.
Ian Silber
+1  A: 

Here's an answer I got in the Drupal forums which worked perfectly:

The following assumes that artist is the title field of artist, song the title field of song.

Create a view with the following Fields: Title (label set to Artist) Filters: Node: Published set to yes, Node: Type set to Artist.

You should now have a view that lists all artists.

Add a relationship on the node reference field in artist for songs, make sure delta is 'all'. When adding the next two fields use the relationship Field: Node: Title (label set to Song) Field: Content: Length (or whatever you call the field)

Now under "Basic settings" set style to 'table'.

http://drupal.org/node/825168

Ian Silber