If a repository item has a property with the cascade="delete" attribute set, when you remove the repository item, any items that are referenced by the property are also removed. Also, when you remove a reference to this item, the item is automatically removed. You must take special care in using cascade delete in one-to-many relationships. Do not use cascade="delete" in properties on the “many” side of the relationship that refer to items on the “one” side of the relationship. The item on the “one” side of the relationship cannot be deleted safely, because multiple items may be referring to it.

For example, suppose you have an item descriptor named company with an employee property that references many repository items defined by an employee item descriptor. The employee item descriptor itself defines a company property. In this one-to-many relationship, the employee property in the company item descriptor can use cascade="delete". However, the company property in the employee item descriptor should not use cascade="delete", as deleting one employee item deletes the company item that is referenced by the remaining employee items.

Removing null references

There are a number of cases where you might have a reference to one or more other objects and the referenced object might be removed without explicitly removing the reference from the referencing object. This might occur in a case where the database may not have a references constraint on the columns and may remove the referenced object without updating the referencing object’s property. It can also occur in a case where the referenced item might actually exist, but is currently filtered out by an RQL filter so it appears not to exist.

In these cases, you can cause the referencing object’s reference to be ignored, rather than return an error. Do this by setting the removeNullValues attribute to true in the referencing property. This causes the missing referenced object to return as null for a scalar reference and omitted from the collection that is returned for multi-valued references. For example, a user profile might have a multi-valued property that is a list of favorite articles. Any given article might be deleted or become out of date. You can remove references to articles that are no longer available with the removeNullValues attribute like this:

<property name="favoriteArticles" data-type="list"
          component-item-type="articles">
  <attribute name="removeNullValues" value="true"/>
</property>
 
loading table of contents...