OCLOperators OnDelete
This page was created by Hans.karlsen@mdriven.net on 2022-04-05. Last edited by Hans.karlsen@mdriven.net on 2025-03-18.

OnDelete is called when an object is deleted - much like a destructor.

The delete may fail due to the object - or one of the objects aggregates that is deleted as a consequence of Cascading delete - is not ready for delete (as if it has still associations not included in the cascading delete).

This may pose problems for you in certain scenarios like for example this example:

Documentation OCLOperators OnDelete 1734385240315.png

In the example above - when a Class1 object is deleted - almost all follow the Cascade delete rules due to the use of Composite on the association ends - however if the link from a class4-object has some class3-objects in its association that is "only" aggregate - the delete will halt - stating that the association end Class4-Class3s is not empty.

In this scenario you might find it beneficial to implement the OnDeleteReasonSolve(reason:string) method.

The OnDeleteReasonSolve method gives you the reason in the incoming parameter - but you may now what the problem is already and just implement the OnDeleteReasonSolve method with action language:

self.Class3s->clear 

The check will then be done again - and if no reasons not to delete remain the delete will go through.

See also: OnCreate, OnUpdate, OnStateChange

MDriven Chat

How would you like to chat today?

Setting up your conversation…

This may take a few moments