How to create in XML records with circular reference

Some data model design may contain circular reference.
For example in the module party_relationship, the relation type can have a reverse relation that point to itself or to another relation type with a reverse relation to the initial relation type.

To create such record via XML data, you need to update already created record inside the same module. This is normally forbidden because the id of a <record/> must be unique. The way to get around this constraint, is to use for the second definition the id prefixed by the module name.
Here is some examples:

<record model="party.relation.type" id="relation_type_child">
    <field name="name">Child</field>
</record>
<record model="party.relation.type" id="relation_type_parent">
    <field name="name">Parent</field>
    <field name="reverse" ref="relation_type_child"/>
</record>
<record model="party.relation.type" id="my_module.relation_type_child">
    <field name="reverse" ref="relation_type_parent"/>
</record>
<record model="party.relation.type" id="relation_type_sibling">
    <field name="name">Sibling</field>
</record>
<record model="party.relation.type" id="my_module.relation_type_sibling">
    <field name="reverse" ref="relation_type_sibling"/>
</record>
3 Likes