Fix for Model::saveAll bug, closes #4466

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6823 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
the_undefined 2008-05-13 00:39:29 +00:00
parent 0b1f7b9151
commit 232e3f7ec1
3 changed files with 39 additions and 0 deletions

View file

@ -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) {

View file

@ -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() {

View file

@ -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') {