Permalink
Browse files

Avoid running validation again, when saveAll() is called with 'valida…

…te' => 'first'
  • Loading branch information...
1 parent d136fac commit 9556ff714dfb65af705e917b215f98ca9b92c90b @ceeram ceeram committed Apr 16, 2012
Showing with 2 additions and 2 deletions.
  1. +2 −2 lib/Cake/Model/Model.php
View
@@ -2044,7 +2044,7 @@ public function saveMany($data = null, $options = array()) {
if ((!$validates && $options['atomic']) || (!$options['atomic'] && in_array(false, $validates, true))) {
return $validates;
}
- $options['validate'] = true;
+ $options['validate'] = false;
}
if ($options['atomic']) {
@@ -2175,7 +2175,7 @@ public function saveAssociated($data = null, $options = array()) {
if ((!$validates && $options['atomic']) || (!$options['atomic'] && in_array(false, $validates, true))) {
return $validates;
}
- $options['validate'] = true;
+ $options['validate'] = false;
}
if ($options['atomic']) {
$db = $this->getDataSource();

5 comments on commit 9556ff7

@teddyzeenny
Contributor

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.

@ceeram
Member

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

@teddyzeenny
Contributor

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.

@cvandeplas
Contributor

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

@ceeram
Member

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.

Please sign in to comment.