Closed cornernote closed 8 years ago
After thinking about it a bit more I have decided that it's best to not manipulate the model's attributes inside the workflow events. It should be done in the model's beforeSave()
.
I'll leave this open so you can have a read, but feel free to close it off.
hi @cornernote, indeed the before family events are designed to validate that the action (in your case "leaving unit/packed" status is allowed based in the current state of your model. Modifying anything from this kind of event handler is not a good idea as in the end, the transition may be rejected (i.e. another before event handler invalidates it) but the modification would persist.
So using beforeSave()
could be a good solution (other option being the after event family)
ciao
The problem is a little complex, but I'll do my best to try to simplify it.
I want to get a list of the next statuses, running the beforeEvents to ensure they are allowed.
The flow is:
unit/despatch
unit/packed
(current status)unit/collected
(I want to move here, but only allowed if there is a package that is collected)It should be allowed to move to
unit/collected
, because it has a$unit->package->collected=1
, however because all the before events are triggered, the$unit->package_id
is unset by the first method, therefore the second method can't detect that the package is collected and then invalidates the event.Perhaps internally in
getNextStatuses()
you should clone the object.Or perhaps I shouldn't be using the
beforeLeave
events to manipulate the model's attributes, and should instead be doing it in the model'sbeforeSave()
.Let me know your thoughts... if this even makes sense. :)