Can I add a node reference in CCK from wrong side?

jtbayly - February 12, 2009 - 16:00

I've been reading and reading about node referrer, node relativity, node reference, etc. and I'm stuck.

What I want to be able to do is allow users to add a node reference from either side of the relationship. Unless somebody can convince me it is a good idea, I would rather not have the reference recorded in two places (ie both nodes referencing each other).

Here is an example.

1. I create a 'person' content type and an 'event' content type
2. I add a node reference field to 'event' that is called 'volunteer'

I want my users to be able to create the connection regardless of whether they are editing the event or the person. Of course, by default they will be able to add a volunteer to an event while they are editing that event. (And with the "popups: add and reference" module they will even be able to create a new person on the fly, if the person doesn't exist yet.) But I also want them to be able to be editing the person and decide to add them as a volunteer to an event.

Seems relatively straightforward to me, but I'm completely confused about how to start. Some modules that seem to solve this problem are only for D5, which doesn't help my sanity.

Any suggestions?

Thanks,
-Joseph

If I'm understanding right,

sunset_bill - February 12, 2009 - 17:38

If I'm understanding right, what you end up with in 'event' is a list of volunteers as node references to their 'person' nodes? Couldn't you add a node reference in 'person' that links to events they've volunteered for?

salud,
Bill

you got it, but...

jtbayly - February 13, 2009 - 15:39

That's right. However, that is exactly what I don't want to do unless there is no other way. I don't want the data stored in two places. What happens if they get out of sync? Why should I waste the space and processing power storing the same piece of information in two places and keeping it in sync? It just seems like a bad design to me.

However, I'm pretty new to Drupal, so maybe I don't understand something here...

Let me know if I'm just being dense or contrary here.
-Joseph

Ah, but that's the lovely

sunset_bill - February 13, 2009 - 21:03

Ah, but that's the lovely thing about node references, they're really just links that reference existing nodes. You've already got nodes for events and people, so all you're doing with node references is putting links in one type that point to nodes of the other type. As for staying in sync, you are probably going to have some admin there, but if you've got a reference to a node that goes away, the reference should go away, too.

No worries, it took me awhile to get the hang of node references, too.

I think you've missed part of my problem

jtbayly - February 14, 2009 - 22:39

I'm not so concerned about a node going away that is referenced by another one, although it would be nice to be able to enforce constraints on that sort of thing.

I think what I'm really discussing is basically a workflow problem. I want the user to be able to create the reference regardless of which type of node they happen to be editing. Here is a link to a comment from somebody who seems to be discussing the same thing I am. He calls it "two way links". http://groups.drupal.org/node/13162#comment-49816 (note that the post itself, and every other comment under it is discussing something very different.)

If I create a node-reference field in event that points to person, and a node-reference field in person that points to event, it does indeed allow the user to edit it on either side, but the data is only half-entered unless they do it from both sides. Because if they are editing an event, and add a reference to a person, then when they go edit the person, the node reference field in the person will be empty. There are two fields at that point, storing the same data, which seems really dumb to me. (But that doesn't seem to be what you were advocating, now that re-read it. It seems you were recommending switching which side I made the connection from. Switching sides does not help. I want the user to be able to make the reference regardless of which type of node they happen to be editing.)

Ultimately what I am looking for is quite strange, because essentially, I want the ability to make a change to one node while I am editing a different one. Let me try to describe why:

Person and Event = Node types
Events have a node-reference field called "volunteer" that can only point to nodes of type "Person"

Node "John Smith" = Person
Node "Jane Doe" = Person
Node "Cancer Survivor Dinner" = Event

User can do *both* of the following:
While editing "Cancer Survivor Dinner" add John Smith as a volunteer
AND
While editing Jane Doe add her as a volunteer to the "Cancer Survivor Dinner".

Since the node reference is actually stored in the event, that means that I'm in reality requesting to be able to add a node reference to an event while I'm editing a person. That seems strange, but I'm sure you can see the usefulness of being able to do it from either side of the connection. There is simply no reason to limit the user to one or the other. In fact, both make a lot of sense. (If I need to explain why, I can.)

It is really simple to *display* the data on either side (for example using views). But I can only edit it from one side. Is there not a module that allows me to edit a node reference from both sides--both the referencing node, and the referenced node?

Thanks again for your help. If I'm completely missing the boat, let me know.

ahh

sunset_bill - February 15, 2009 - 15:22

That does sound a bit trickier. Adding a reference to an existing volunteer while editing an event seems like a pretty straightforward node reference, but functionality like adding a person to an event's volunteers list while editing the person is something I think is probably going to require some hacking as far as I know. I don't know of any modules for that, myself.

best luck!

Node Relationships

thaddeusmt - September 1, 2009 - 05:59

check out:
http://drupal.org/project/noderelationships

might do the trick?

 
 

Drupal is a registered trademark of Dries Buytaert.