StateMachine event triggering on parent-child datastructure change

I wonder what is the easiest way to solve following use case:

Imagine a datastructure - parent with child entitity. Then a workflow that in

  1. first step loads the data for that structure from db
  2. modifies the data by a transformation - modify one ore more child entity rows.
  3. saves the modified data structure to db

I would like to trigger validation on any change of child structure (child added/modified/deleted) . This validation would validate all the data of childs rows and parent row. I would like the validation to be called only once even though there could be more child changes at once. (not to repeat the same validation)

I would like to solve it with state machines (not call validation explicitely as an extra step from wf),

There is no built-in solution for that.
If there is a state-machine event subscribed on change of each “detail” that would execute a validation on the whole master-detail then this event will be called as many times as many details are changed, duplicating the effort.


Design a field in the master entity which you will always update when touching the detail records. E.g DetailLastUpdated. This way you will fire the event on the master entity every time the details will be updated and it will always run just once.
There is another positive side of this–you will see an information that the detail records changed in the Audit Log, too (not all the data from the children records but just the time stamp).