diff --git a/cake/libs/model/model.php b/cake/libs/model/model.php index 100d331b5..32a19a717 100644 --- a/cake/libs/model/model.php +++ b/cake/libs/model/model.php @@ -1593,6 +1593,7 @@ class Model extends Overloadable { if (Set::numeric(array_keys($data))) { while ($validates) { + $return = array(); foreach ($data as $key => $record) { if (!$currentValidates = $this->__save($record, $options)) { $validationErrors[$key] = $this->validationErrors; @@ -1624,7 +1625,6 @@ class Model extends Overloadable { break; case ($options['validate'] === 'first'): $options['validate'] = true; - $return = array(); break; default: if ($options['atomic']) { diff --git a/cake/tests/cases/libs/model/model_write.test.php b/cake/tests/cases/libs/model/model_write.test.php index 7de1d0820..497bc56fa 100644 --- a/cake/tests/cases/libs/model/model_write.test.php +++ b/cake/tests/cases/libs/model/model_write.test.php @@ -3584,6 +3584,65 @@ class ModelWriteTest extends BaseModelTest { $this->assertEqual($result[0]['Comment'][0]['comment'], 'Only new comment'); } +/** + * test saveAll()'s return is correct when using atomic = false and validate = first. + * + * @return void + */ + function testSaveAllValidateFirstAtomicFalse() { + $Something =& new Something(); + $invalidData = array( + array( + 'title' => 'foo', + 'body' => 'bar', + 'published' => 'baz', + ), + array( + 'body' => 3, + 'published' =>'sd', + ), + ); + $Something->create(); + $Something->validate = array( + 'title' => array( + 'rule' => 'alphaNumeric', + 'required' => true, + ), + 'body' => array( + 'rule' => 'alphaNumeric', + 'required' => true, + 'allowEmpty' => true, + ), + ); + $result = $Something->saveAll($invalidData, array( + 'atomic' => false, + 'validate' => 'first', + )); + $expected = array(true, false); + $this->assertEqual($result, $expected); + + $Something =& new Something(); + $validData = array( + array( + 'title' => 'title value', + 'body' => 'body value', + 'published' => 'baz', + ), + array( + 'title' => 'valid', + 'body' => 'this body', + 'published' =>'sd', + ), + ); + $Something->create(); + $result = $Something->saveAll($validData, array( + 'atomic' => false, + 'validate' => 'first', + )); + $expected = array(true, true); + $this->assertEqual($result, $expected); + } + /** * testUpdateWithCalculation method *