Title: Delete Rules

Delete Rules

One of the columns in the Modeler ObjRelationships panel is "Delete Rule". It tells Cayenne what to do with related objects when a source object of the relationship is deleted. Cayenne will use this delete rule to perform cleanup of other objects after a given object was deleted from the graph.

Default delete rule is No Action, meaning just that - when an object is deleted, no changes should happen to objects related to this object via a given relationship. Though this is a default, it is not very useful, and can lead to object graph corruption in many cases. It is developer responsibility to select a more meaningful delete rule. The choices are: "Nullify", "Cascade" and "Deny". Each one of them is explained below.

Cayenne Delete Rules vs. DB Delete Rules
Some databases allow to define delete rules logically similar to the rules described above. Cayenne rules differ from DB rules in that they deal with object graph instead of relational schema. Some changes to the object graph will result in database operations (e.g. resetting FK to NULL as a result of Nullify rule), some others will not (e.g. removing a deleted DataObject from the to-many array as a result of another Nullify rule).