Migrate Node Reference Field to Relations
The following code (Rules export) allows me to move nodes from a reference field to a relation field:
The Relation module has integration with Rules, primarily to allow creating new relations. It is also possible, but slightly awkward, to fetch and manipulate relation entities with Rules.
This documentation page assumes that you are already familiar with the basic concepts in Rules – in particular with lists.
To create a new relation in Rules, you must first have a list of entities that should be used as endpoints in the relation. The following steps will provide you with actions to create brand new relation in your rule:
Possible stumbling block:
View a screencast about creating relations with Rules
Using Rules you can also load existing relations, and perform actions on them or their end points. However, this is complicated by the fact that you usually need a good identifier for the relation you want to fetch – such as its relation ID or the entire list of endpoints.
Assuming you have one of these, you can load a relation using one of the load entity by ID or load entity by property action, fetching the entire relation entity into your rule.
Once that is done, you can access the end point objects as a list, either by looping through the list or by using data selection and selecting (say) the first end point directly.
Possible stumbling block:
The following code (Rules export) allows me to move nodes from a reference field to a relation field: