2

I'm confused with Views' query altering and adding joins. Need help (or at least a comprehensible documentation with code samples, because I've never found one).

Here is what I'm trying to do: I have 2 node types, Writers and Books. I use taxonomy to group Books by Writers. I've created a field in my taxonomy terms that references respective Writer articles. It looks like this:

  • Books by Writers (dictionary)
    • Books by Isaac Asimov (taxonomy term, WriterId = 1 - references Isaac Asimov node)
      • I, Robot (Book node)
    • Books by Harry Harrison (taxonomy term, WriterId = 2 - references Harry Harrison node)
      • West of Eden (Book node)

Now I'm trying to build a view that looks like this:

  • Isaac Asimov (Writer node title)
    • I, Robot (Book node title)
  • Harry Harrison (Writer node title)
    • West of Eden (Book node title)

All in all, I need something like Book Nodes join Taxonomy Terms join Writer Nodes. In Views UI I'm able to display Book titles and add a relation to Taxonomy so that I can display all Taxonomy term fields. It looks like this:

  • 1 (WriterId from taxonomy term)
    • I, Robot
  • 2 (WriterId from taxonomy term)
    • West of Eden

How do I join Taxonomy and Writers to get access to Writer node titles?

2

As I understand you don't really need taxonomy here. Instead you can reference Book node to Writer node directly.
Of course, you can solve the problem without modifying your current structure. I will show how to create such View using Entity reference as referencing field. I recommend this module for creating references in Drupal 7 as it is powerful and stable.

  1. First, create new View for Books content type: enter image description here
  2. Add relationship to taxonomy term: enter image description here
  3. Now you can add one more relationship to Writers nodes. Here Entity reference comes into play:
    enter image description here enter image description here
  4. Now you can output all you want from Book node, from relative taxonomy term or from relative to that term Writer node. Just select appropriate relationship to use:
    enter image description here
    Here I added title from Writer node and excluded it from display.
    You may want to group output by writer and it can be done in Format settings: enter image description here

If you didn't use unnecessary dictionary, you would not need the second step.

About a year ago I started with NodeOne series Taming the Beast: Learn Views with NodeOne and Using the Reference modules by Johan Falk and I hope this information will help you too.


Done with love to Isaac Asimov.

  • Oh yessss. It workssss. – Ari Linn Jun 26 '12 at 20:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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