I'm new to Drupal, so my apologies if this is a newbie question, or if I'm applying SQL concepts to Drupal in an inappropriate way. What I'm trying to learn how to do is set up a many-to-one relationship in a view. I've found several tutorials that show how to do a one-to-many relationship -- for example, show a list of departments with a sub-list of employees in each department. What I need to do is go in the opposite direction.
Suppose I have the following content types:
office
* city (text)
employee
* works_at (nodereference to office)
* salary (decimal)
How would I set up a view to show an employee with his salary field (from the employee node) as well as what city he works in (from the office node pointed to by the works_at nodereference field)?
Comments
using views relations
I may need a little more to answer properly, but it sounds like you are still doing a 1 to many - 1 employee to many offices.
Assumptions: employee name and salary are single value fields. works_at is a 1-n value field.
Set up a new view to pull employee nodes.
Add a relationship to the city via the nodereference works_at field - call it (office)
Add field for employee name and salary.
Add field for works_at - uncheck the 'group multiple values' box.
Preview. If you the employee works at multiple cities they should show up as individual roles;
employee - salary - works_at delta 0
employee - salary - works_at delta 1
Add field for the city field and use the (office) relationship. Now you should see the office related to each works_at reference.
I'm unique, just like everybody else.
If I helped, please pay it forward, backward or sidelong.
Thanks!
Thanks for the help. Actually the thing I was trying to figure out was slightly different, but your advice nudged me in the right direction. (To get City to display, I had to add it and set "office" under "use relationship").