Search code examples
cascadesap-commerce-cloud

How to define cascade delete in the Hybris items.xml?


I want to remove child objects automatically on removable of the Parent object.

For instance, I have types Car and Engine. The car has an attribute Engine. When Car object is removed, Engine object that is bound to this Car should be removed automatically.

Thanks in advance, guys


Solution

  • Use the "partOf" modifier:

    <itemtype code="Car" ...>
      ...
      <attributes>
        ...
        <attribute qualifier="engine" type="Engine">
          <persistence type="property" />
          <modifiers partof="true" />
        </attribute>
      </attributes>
    </itemtype>
    

    Can also be used with relations:

    <relation code="CarToEngineRelation"...>
      <sourceElement type="Car" ...>
      </sourceElement>
      <targetElement type="Engine" ...>
          <modifiers partof="true"/>
      </targetElement>
    </relation>