0

Background (simplified)

We're collecting data for a study in which participants come in on several occasions to have health measures taken. We have two custom node types: Participant stores background data about a person, and Visit stores information from a single visit (e.g., their blood pressure that day). Each Visit is related to one Participant via a field created by the Node References module.

On each visit, a participant might qualify for a one-time reward. Visit nodes have a reward_visit field indicating whether the participant earned a reward on this visit, and Participant nodes have a reward_ever field indicating whether the participant has ever received a reward.

Question

I'd like to set up the following behavior: If a Visit node is created where reward_visit was set to Yes, also set reward_ever to Yes in the corresponding Participant node.

Is there a way to make this happen automatically, using Node References or some other relations module? I could custom-code it using hook_node_insert() or something, but I'd like to know if there's already an accepted way.

0

UPDATE: The answer to this question is "Rules". I hadn't learned about them at the time. With a rule, you can choose to trigger on saving or updating new content and use conditions to limit it to the content type in question. For the action, choose "set a data value" and the relation between the two nodes should allow you to select the relevant field on the node you just created as the source, and the relevant field on the related node as the value to set.

Original answer: I ended up writing a small custom module that implements hook_node_insert and hook_node_alter for visit nodes. It gets the nid of the related participant from the submission, gets it using node_load(), changes the relevant values, and saves it using node_save(). I still suspect there's a less kludgy solution, but this seems to work perfectly well.

| improve this answer | |

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.