diff --git a/cake/libs/model/model.php b/cake/libs/model/model.php index f7cfd6787..841302610 100644 --- a/cake/libs/model/model.php +++ b/cake/libs/model/model.php @@ -1365,6 +1365,9 @@ class Model extends Overloadable { $return[$this->alias][] = $validates; } foreach ($data as $association => $values) { + if (!$validates) { + break; + } if (isset($associations[$association])) { $type = $associations[$association]; switch ($type) { diff --git a/cake/tests/cases/libs/model/model.test.php b/cake/tests/cases/libs/model/model.test.php index f694295d6..9f835b95e 100644 --- a/cake/tests/cases/libs/model/model.test.php +++ b/cake/tests/cases/libs/model/model.test.php @@ -2142,6 +2142,37 @@ class ModelTest extends CakeTestCase { $result = $this->model->findById(2); $expected = array('First Comment for Second Article', 'Second Comment for Second Article', 'First new comment', 'Second new comment'); $this->assertEqual(Set::extract($result['Comment'], '{n}.comment'), $expected); + + $result = $this->model->saveAll( + array( + 'Article' => array('id' => 2), + 'Comment' => array( + array('comment' => 'Third new comment', 'published' => 'Y', 'user_id' => 1), + ) + ), + array('atomic' => false) + ); + $this->assertTrue($result); + + $result = $this->model->findById(2); + $expected = array('First Comment for Second Article', 'Second Comment for Second Article', 'First new comment', 'Second new comment', 'Third new comment'); + $this->assertEqual(Set::extract($result['Comment'], '{n}.comment'), $expected); + + $this->model->beforeSaveReturn = false; + $result = $this->model->saveAll( + array( + 'Article' => array('id' => 2), + 'Comment' => array( + array('comment' => 'Fourth new comment', 'published' => 'Y', 'user_id' => 1), + ) + ), + array('atomic' => false) + ); + $this->assertEqual($result, array('Article' => array(0 => false))); + + $result = $this->model->findById(2); + $expected = array('First Comment for Second Article', 'Second Comment for Second Article', 'First new comment', 'Second new comment', 'Third new comment'); + $this->assertEqual(Set::extract($result['Comment'], '{n}.comment'), $expected); } function testSaveAllTransaction() { diff --git a/cake/tests/cases/libs/model/models.php b/cake/tests/cases/libs/model/models.php index 5bb37c672..10ad1252b 100644 --- a/cake/tests/cases/libs/model/models.php +++ b/cake/tests/cases/libs/model/models.php @@ -101,6 +101,11 @@ class Article extends CakeTestModel { var $hasMany = array('Comment' => array('dependent' => true)); var $hasAndBelongsToMany = array('Tag'); var $validate = array('user_id' => VALID_NUMBER, 'title' => array('allowEmpty' => false, 'rule' => VALID_NOT_EMPTY), 'body' => VALID_NOT_EMPTY); + var $beforeSaveReturn = true; + + function beforeSave() { + return $this->beforeSaveReturn; + } function titleDuplicate ($title) { if ($title === 'My Article Title') {