drupaldrupal-7drupal-modulesdrupal-nodes

Relationship between noderefernce fields


I have two content types: Region and City, Region node includes City node, every City node is related to some Region node, how I can create relationship for this situation: when I create Region node and refer a City node in a field, all City nodes have its Region referencing field set to this Region node and vice-versa?


Solution

  • You can use Corresponding Entity References to achieve this.

    Follow this steps:

    1. Create two content types: Region and City.
    2. Insert entity reference field: Cities in Region and Region in City.
    3. Now enable Corresponding Entity References and update its configuration by going on your site: Configuration >> System >> Corresponding entity references.
    4. Check this configuration: Correspond Region on node(s) of type city with Cities on node(s) of type region. enter image description here
    5. Now in next tab Updating existing entities of entity type: node. enter image description here