-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid running validation again, when saveAll() is called with 'valida…
…te' => 'first'
- Loading branch information
Showing
1 changed file
with
2 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9556ff7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This reduces redundancy, but causes the save to skip all beforeValidate callbacks... any data changed during these callbacks no longer applies to the actual save.
9556ff7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Imo you shouldnt use 'validate' first option then, but true instead
I feel that it only used to work because it incorrectly ran validation twice
9556ff7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see your point, but this will break many applications though, as it did mine :)
How about we make it call beforeValidate but skip the validation? You think that would be a good idea ?
Another option would be to fetch the new data from the model (after the initial validation) and save that... I don't know if i just made sense.
9556ff7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change broke my application because the behavior is not as expected from the documentation. (before validation there is always the beforeValidate executed)
I reported a bug here: http://cakephp.lighthouseapp.com/projects/42648-cakephp/tickets/2893
9556ff7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has been fixed in 2.1 dev branch and will be in next release 2.1.3
[Edit:clarification]
Before this change, validation was run twice, now just once. beforeValidate is still being executed, but if data is altered in the callback those changes are lost. The commit(s) that fixes the loss of changed data will be in the 2.1.3 release.