Skip to content

Preserves "Dirty" flags for afterSave hooks.#72

Merged
romaninsh merged 1 commit intodevelopfrom
feature/preserve-dirty-flags-across-relad
Jul 25, 2016
Merged

Preserves "Dirty" flags for afterSave hooks.#72
romaninsh merged 1 commit intodevelopfrom
feature/preserve-dirty-flags-across-relad

Conversation

@romaninsh
Copy link
Copy Markdown
Member

@romaninsh romaninsh commented Jul 25, 2016

when using afterSave hooks you might be interested to look at the dirty fields. Unfortunately using the "reload after save" mechanics will cause it to reload the record which resets dirty fields.

This fix:

  • will memorize dirty fields before reloading (A)
  • will memorize dirty fields after reloading (B)
  • will restore dirty fields A then call hooks.
  • will merge with dirty fields B after hooks.

Goal of this PR:

  • make sure you get all dirty fields inside afterSave hook regardless if "reload after save" is On/Off.
  • if you perform any changes, in afterSave - do not forget those.
  • if afterLoad performs any changes as a part of reloading, keep those in our dirty array

No test-scripts provided for the above cases.

Comment thread src/Model.php
*
* @return $this
*/
public $_dirty_after_reload = [];
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be defined at top of Model class file.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i thought since it's $_xx and we don't want anyone to use it but can't make it "private" due to our other class referring to it and also because our style checkers didn't complain, then we can leave here.

@romaninsh romaninsh merged commit 63c75ad into develop Jul 25, 2016
@romaninsh romaninsh deleted the feature/preserve-dirty-flags-across-relad branch July 25, 2016 13:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants