Reverse Node References

Here is a use case that happens to me all the time, and I am boggled that I haven’t found a simpler solution. I have a bunch of Faculty nodes, and I want to specify that some of them belong to various Committees. I want a committees page that has a linked listing of committees, and then each committees page should have a description of the committee and a linked list of all the members. Also it needs to be dead simple for a non-skilled content editor to edit the committee descriptions and to create new faculty without needing to create all the committees ahead of time.

You can do almost all of this with Taxonomy free tagging and Views 2, but the easily editable per-committee description trips you up. For that you need a node type with a Reverse Node Reference. I am open to suggestions, but here is how I do it:

  • Views 2
  • CCK’s Node Reference
  • Popups: Add and Reference

  1. Create a Committee node type.
  2. Add a Node Reference to the Faculty node type called ‘committee’.
  3. Use Views 2 to create a reverse-reference view (These instructions are based on Create a view on a node reference field )
    1. Add a view with view type ‘node.
    2. In Relationships section select the committee node reference field and enable ‘Require this relationship’.
    3. In Arguments section select ‘Node:nid’ – this will be used to enter the Artist’s node id.
      1. In Arguments Configuration, select the Relationship ‘Committee’.
  1. Use the appropriate Sort criteria. I used ‘Last Name’.
  1. Then create a node-committee.tpl.php in your theme, and add:

<?php
  $view
= views_get_view ( 'committee_members' );
  print
$view -> preview ( 'default' , array( $node -> nid ));
?>

This accomplishes all my goals. The editor can create a new committee either from the “Create Content” page, or while creating a new faculty member, and the committee description is easily edited. I am a little unhappy having to resort to the theme layer. Maybe I won’t need to once the viewfield module releases a stable Drupal 6 version.

How about...

http://drupal.org/project/viewreference ?

This has (or purports to have) similar functionality to viewfield, but has a stable release for D6.

I haven't used it as yet, but probably will be, quite soon - for similar reasons, I expect!

I tried it. It can achieve

I tried it.
It can achieve this functionality, but at the cost of requiring the content editor to paste the name of the new node into an arguments text field. There seems to be no way to automatically pass the node id as an argument.

NodeReferrer

This sounds a lot like what the NodeReferrer module did for Drupal 5. There's no D6 version of that module (yet?), but anyways I find it great that this can now be done in Views itself without any further modules :)

The super cool thing would

The super cool thing would be if the Drupal 6 version of NodeReferrer would automatically create the view for you.

D6 of Nodereferrer

http://drupal.org/node/259837#comment-1040436

Seems to be working for many people

just a tip

you may also use

<?php
print views_embed_view (...);
?>

This only works for the first item in a node reference results..

Unfortunately Relationships seem to occur at a 1:1 level.

So say I a content type of FAQ, and it is extended with node ref. In an example node, I edit and add 4 nodereference links to other (related FAQs).

Now in Views, I have 2 choices:
a) I can build FOUR relationships, indexed by Delta, and arrive at my 4 values. But got help me if the content type allowed "unlimited" noderef links. :-)

b) I can have the views grab the raw output of Node Reference. Unfortunately, Node Reference output is pretty limited in that it does not present additional fields like NID and Title... it hardcodes a URL around the Title (and exposes no other data about the referred node). The /node/123 URLs are OK for simple Drupal sites, but if you use custom pathing (as is done with Panels pages) then you are stuck. In your Views templates however you can chop up the NodeRef URLs and reconstruct them as you needed... but it is a pain.

But if you need just 1 result from the Views Relationship, this IS a good solution. :-)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.