Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

afterSave and hasSnapshotData strange behaviour

Hello, yesterday I updated php7.0-phalcon and I noticed a problem: If I try to use $this->getSnapshotData() in afterSave function, function returns NEW values, not OLD ones like it used to return until last update, which I consider normal behavior. If need new values i already have them in $this->column. How can I get old values snapshot in afterSave ? Thanks

edited Apr '17

Just move code from afterSave to beforeSave(as it should be) or wait for 3.2.0 which added hasUpdated/getUpdatedFields to check if field was updated or which fields were updated. It was consider as a bug that snapshot is not updated after succesfull save/create. And telling hasChanged that it was changed even after save it wasn't. Related issues:

I guess this is just arguable if this was consider as normal or as a bug, i think for most of people it was consider as a bug, that after save snapshot should be updated to represent current value so after changing some field again it would be correctly returned as changed and those which didn't changed correctly returned as not changed.

I think i will add hotfix for this so you can keep old way.

edited Apr '17

Clearly is a bug, because we can get new values from $this->column, but old ones ? "Just move code from afterSave to beforeSave" - I do status change verification to send confirmation emails just ONCE from status change, same on orders after processing, in some places I need inserted ID in aftersave, so no is not that easy. I will do a hack untill you release a fix. Thanks!

I accepted answer in mistake :(

edited Apr '17

Well i will release fix just to enable old way, like not update snapshot. Right now it's fixed and correct behavior is to update snapshot after save. In phalcon 3.2 there will be added:

  • way to check if field was updated after save, and get updated fields using new methods
  • way to disable snapshot update on save/create so those issues are posted will be still happening

So with this second way by using php.ini or Model::setup() you can enable old way and have code working with thing consider as a bug if in your opinion snapshot should not be updated and it's normal, for most it was consider as a bug.