Circular Referencing with Content types and Views

Hi all,

I have a query about views and node references. I have 2 content types called Class & Resources.
The class content type has a node reference field called AssociatedResources and the Resources content type has a node reference called AssociatedModule

I would like to have a number of users with permission to create Resources and as part of that process associate it with a particular class using the associated class list of nodes

I need to restrict the class content type creation & edit permissions to a smaller group but would also like the associated resources to be listed automatically if and when a new resource is associated with that module and not require the editor to edit each class to update the select widget list.

Is there a way

  • When I define the class content type to say that the associated resources field should pass class content's own node ID (which I assume is unknown until the node is saved for the 1st time) as the argument to the GetAssociatedResources view?
  • Would that also automatically list them without needing the editor to edit each class to see if new resources should be displayed?
  • Groups:
    Login or register to post comments

    In the arguments section of

    alanburke's picture
    alanburke - Mon, 2010-02-22 11:08

    In the arguments section of the view, you'll probably need to write some php code to get the nid of the node being displayed... if I understand correctly.


    I might be overanalysing

    Chris Graham's picture
    Chris Graham - Mon, 2010-02-22 12:02

    I might be overanalysing things here and I may be about to make myself look like an ass but here goes.

    If I understand things you want to have a group of users with permissions to create Classes and everyone else would be able to add Resources only - just roles and permissions will do the trick there.

    Now, if I am reading things right, you have overcomplicated the relationships a bit. If the Resources should belong to the Class then the nodereference should be on the Resource content type to associate it with a Class (you don't need 2 references), this would mean that when creating a Resource you would see a list of Classes in the widget that will update when your smaller group of users with Class create permissions adds a Class.

    After this you would then set up your view to take an argument of your nodereference field (which would be your Class nid) - I think you are calling it AssociatedModule - and then filter by Type: Resource and hey presto, you should have a view of all Resources that have a nodereference that refers to that Class.

    Now as Alan has mentioned you would need to pass the nid for the Class through as an argument to the view so when setting up your argument under "Action to take if argument is not present:" select "Provide default argument" and choose "Node ID from URL". That should do the trick, if you attach your view to the Class node or pop it in a block on Class pages it should display the relevant Resources.

    I think that is what you are trying to achieve and if so take a look at http://drupal.org/project/nodereference_url too - with this you can tell it to put a link on your Class nodes to create a Resource which will auto-select the Class (I've found it very handy). If it isn't what you wanted then apologies for making you read this rather long post ;)


    Thanks Alan & Chris for

    mobcdi - Mon, 2010-02-22 14:27

    Thanks Alan & Chris for replying,

    I went with the nodereference url mainly because of my overriding personal rule to avoid writing code no matter how small if at all possible. You were right on in your analysis Chris. There is a video link on the nodereference url project page to http://mustardseedmedia.com/podcast/episode37 that covered exactly what I was hoping to do. I just needed to make a few changes to my View and add a "Node Content" display