OCLOperators OnDelete
No edit summary
No edit summary
Line 12: Line 12:
In this scenario you might find it beneficial to implement the OnDeleteReasonSolve(reason:string) method.  
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:  
The  OnDeleteReasonSolve method gives you the reason in the incoming parameter - but you may know what the problem is already and just implement the  OnDeleteReasonSolve method with action language:  
  self.Class3s->clear  
  self.Class3s->clear  
The check will then be done again - and if no reasons not to delete remain the delete will go through.
The check will then be done again - and if no reasons not-to-delete remain the delete will go through.


OnDeleteReasonSolve is a special name recongnised by the framework - much like OnDelete.
OnDeleteReasonSolve is a special name recognized by the framework - much like OnDelete.


If no reason is found OnDeleteReasonSolve is not called.
If no reason is found OnDeleteReasonSolve is not called.


If you do not solve the complete reason in OnDeleteReasonSolve the OnDeleteReasonSolve will be called again with the new main reason.
If you do not solve the complete reason in OnDeleteReasonSolve the OnDeleteReasonSolve will be called again with the new top reason.


If you fail to solve the reason - the same exception is thrown stating the reason to the user.
If you fail to solve the reason - the same exception is thrown stating the reason to the user.

Revision as of 21:57, 16 December 2024

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 know 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.

OnDeleteReasonSolve is a special name recognized by the framework - much like OnDelete.

If no reason is found OnDeleteReasonSolve is not called.

If you do not solve the complete reason in OnDeleteReasonSolve the OnDeleteReasonSolve will be called again with the new top reason.

If you fail to solve the reason - the same exception is thrown stating the reason to the user.

See also: OnCreate, OnUpdate, OnStateChange