cphalcon
cphalcon copied to clipboard
[BUG]: ORM: Model snapshots updated on individual save instead of full transaction.
Describe the bug Model snapshots get updated on save with "orm.update_snapshot_on_save", if for some reason in the save relation chain there is a rollback, the updated snapshot is no longer valid and could lead to issues specially with Dynamic Update.
To Reproduce Save a model with a long chain of relations and fail along that chain in order for the transaction to rollback. Changing any of the models with new data and with Dynamic Update, the previous data that was not commit might not be saved because the snapshot was updated.
Expected behavior Only update snapshots in the model if the transaction is successful, this can be done by using the Model Manager having all snapshots and at the end of the save chain it will replace the snapshots and merge snapshots. It might have a small performance hit but the data will be trustworthy.
To mitigate a large collection of snapshots, WeakMap could be used but only on php8, otherwise a destruct is the better solution.