I'm hoping to get some opinions on the best way to proceed. We are migrating our website from a Microsoft Environment to Drupal 7 and I appear to be having trouble wrapping my head around how to do a couple of things.

We have about 50 locations, and each location might have any number of workers. I have created 2 content types, Location & worker. What I want to do is to create a "view" (for lack of a better term) which will list all of my locations grouped by county. No problem. Now, when the user clicks on one of the locations, I want to show the data for the location (address, phone number, etc) but I also want the location content type to be able to pull a list of workers (from the worker content types) that are at that site.

I have a common field in each content type of location_number, so basically what I need to do is a SQL JOIN operation. I've looked into the Views module and it seems that using that I would have to create a separate view for each location (unless I'm missing something), when what I really want to do is create a more 'generic' view which I can plug into node template and have it auto-generate what I need. I don't want to have to manage 50+ views.

My first instinct is to say write some custom PHP code that gets the data I want. In SharePoint, I would just write a web part with a simple LINQ query right back to the 2 lists and plug it into the page. Is there something similar in to this in Drupal or is there an easier way to go about what I"m trying to do.

Any advice is appreciated.

  • IMHO, this is absolutely something that can and should be done in "Views". I'm not sure why you think you'll need to create a different view for each location.
    – Cravecode
    Commented May 8, 2013 at 17:19
  • I can sympathise; I came from C#/.NET to PHP/Drupal a couple of years ago and it's a difficult transition. As Cravecode said it's very unlikely you'll need a different view for each location; could you expand on how you've tried to setup the View, it might help explain how that conclusion's come about? Also have you come across Contextual Filters? They'll probably help
    – Clive
    Commented May 8, 2013 at 17:34
  • Thanks for the comments. Glad to hear I'm not alone on the transition boat. I must be using Views wrong. I'm reviewing a couple of tutorials to see what I'm doing wrong. I just wanted to really make sure I was going in the right direction and didn't need to write any custom code or a custom module or anything.
    – gev125
    Commented May 8, 2013 at 17:42
  • Ha! Love hearing we're all .NET geeks. I too had such a hard time coming from 10 years of C# to Drupal/PHP. I'll never go back.
    – Cravecode
    Commented May 8, 2013 at 17:56
  • I wouldn't have thought you'd have to write any custom code if you're using the built-in field system, but Views can be daunting. Once you've got the hang of it it's a lifesaver in Drupal though. If you get stuck on specific concepts make sure to search/ask on here; some of the regulars are experts on Views
    – Clive
    Commented May 8, 2013 at 18:28

3 Answers 3


This is core functionality in views and very easy to do with views relationships and entity references. Essentially, what you want to do is create a new entity reference field in your location content type to reference the workers, ex: "Related Workers". You would then add the workers to each of the locations using the normal edit form.

Now in the node output, you'll have a list of these referenced entities as a unordered list of links to the "Related Workers" node which you can customize using the display fields options.

To add these related workers (and all their fields) in a combined view (ex. the join you are referring to) you would just need to create a relationship, using this entity reference field.

This whole process is explained in this screencast from NodeOne



Thank you all for the replies.

I've got the relationships working and everything, however, now I'm having an issue with the actual implementation. I have a contextual filter of Nid on the view and when I use the "Contextual Filter Preview" box in the view creation form, it works beautifully, however, I've added the block to the page as I want it, but no matter which "Location" I click on, all of the workers show up, regardless of location. It's almost like the contextual filter is not working right in practice. Is there something I am missing?

Thanks for the help!


I got it! I wasn't using "Provide Default Value" --> "Content ID from URL" in the contextual filter.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.