Closed (fixed)
Project:
Rules
Version:
7.x-2.2
Component:
Rules Core
Priority:
Major
Category:
Support request
Assigned:
Reporter:
Created:
6 Jan 2013 at 05:41 UTC
Updated:
3 Mar 2013 at 11:19 UTC
Dear all,
1. Rules work this task very good:
- Node Type A and node type B have reference field together
- Create node a of Node Type A, will auto-create node b of Node Type B
- Reference node a to node b and corresponding reference node b to node a
2. But How to do the same task, like this:
- Node Type A and node type B have reference field together
- Node a of Node Type A and node b of Node Type B are existing
- Edit node a, reference to node b ---> How to auto-edit node b reference to node a
Comments
Comment #1
drvdt commentedDear all,
I have found a simple solution. Only need rules module. Create a rule:
1. Event:
- After saving new content
- After updating existing content
(one or both up to you)
2. Conditions
- Content is of type: Chose Content: [node], Content types: Node Type A
- Content is of type: Content:[node:field-reference_to_node_type_b], Content types: Node Type B
3. Actions
- Add an item to a list
Parameter: List:[node:field-refrence_to_node_type_b:field-reference_to_node_type_a], item to add:[node], enforce uniqueness: true
There is all
More information, please see http://drupal.org/node/1836240
Comment #3
razkovnik commentedIt works perfectly when the field-reference_to_node_type_b is limited to 1 value and respectively field-reference_to_node_type_a has unlimited values options.
However - great solution!
Comment #4
bennos commentedyeah this works. What I need is sync between ref field on content type a with unlimited values and ref field with unlimited values on content type b.
Did not found a soulution yet for this.
Comment #5
mabho commentedThis is what I have did for a many-to-many relation in Entity reference. It is kind of complicated, but it works:
*** First: after creating new content of a specific content type ***
1. Event:
- After saving new content
2. Conditions
- Content is of type: Chose Content: [node], Content types: Node Type A
3. Actions
- Add a Loop. I will loop through all the elements of node:field-refrence_to_node_type_b. I am naming the resulting node as $list_item (this is the default name).
- Add a PHP Filter action under the loop - I am doing it with PHP because my entity reference is using views and it looks like Rules cannot identify its content type.
*** Second: After updating existing content of a specific content type ***
1. Event:
- After updating existing content
2. Conditions
- Content is of type: Chose Content: [node], Content types: Node Type A
3. Actions
- Add a Loop. I will loop through all the elements of the unpublished node like this: node-unpublished:field-refrence_to_node_type_b. I am naming the resulting node as $list_item (this is the default name).
- Add a PHP Filter action under the loop - I am going to delete all the old references before the node was updated. This way I don`t have to do a lot of checking to see which elements are new and which elements were removed. I will first remove all the old references.
- Add a Loop again. I will loop through all the elements of the published node like this: node:field-refrence_to_node_type_b. I am naming the resulting node as $list_item (this is the default name).
- Add a PHP Filter action under the loop - I am going to add all references back.
======
Now you would have to apply more or less the same logic to node_type_b. When editing node_type_b the same rules should apply and it should update all the references in node_type_a.