The current decription of Model::dirty indicates that the dirty information is available in all hooks:
* The $dirty data will be reset after you save() the data but it is still available to all before/after save handlers.
However, that is not the case. Model::dirty is reset before the Model::HOOK_AFTER_SAVE spot is executed (taken from current develop):
It is not enough to move the reset after the hook, as Model::reload() also resets dirty. This is where is gets complicated: reloaded model information could be important in the after save hook, as does the dirty information does.
The only fix I can think of is to clone $dirtyRef, assign in to $this right before the hook is executed and then reset it afterwards. Something like:
You can capture the original dirty data in "before update" hook. The dirtiness is logical, before update, the data are dirty as they are. Once they are saved, they are no longer dirty.
The current decription of
Model::dirty
indicates that the dirty information is available in all hooks:* The $dirty data will be reset after you save() the data but it is still available to all before/after save handlers.
However, that is not the case.
Model::dirty
is reset before theModel::HOOK_AFTER_SAVE
spot is executed (taken from current develop):It is not enough to move the reset after the hook, as
Model::reload()
also resets dirty. This is where is gets complicated: reloaded model information could be important in the after save hook, as does the dirty information does.The only fix I can think of is to clone
$dirtyRef
, assign in to$this
right before the hook is executed and then reset it afterwards. Something like:WDYT about this? If you are fine with this, I will create a PR with a change like this and add a test.