From 9e37b6fc26553b4806d043e0d029b05c0e7ee10e Mon Sep 17 00:00:00 2001 From: nate Date: Sun, 9 Mar 2008 07:59:23 +0000 Subject: [PATCH] Adding test cases for saving hasMany associations with saveAll(), ref #4035 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6536 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/model/model.php | 2 +- cake/tests/cases/libs/model/model.test.php | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/cake/libs/model/model.php b/cake/libs/model/model.php index 1fb703cdf..8fd7e23e3 100644 --- a/cake/libs/model/model.php +++ b/cake/libs/model/model.php @@ -1376,7 +1376,7 @@ class Model extends Overloadable { foreach ($values as $i => $value) { $values[$i][$this->{$type}[$association]['foreignKey']] = $this->id; } - if (!$this->{$association}->saveAll($values, array('validate' => 'only'))) { + if (!$this->{$association}->saveAll($values, $options)) { $validationErrors[$association] = $this->{$association}->validationErrors; $validates = false; } diff --git a/cake/tests/cases/libs/model/model.test.php b/cake/tests/cases/libs/model/model.test.php index ee7db70dd..a68228bab 100644 --- a/cake/tests/cases/libs/model/model.test.php +++ b/cake/tests/cases/libs/model/model.test.php @@ -1976,6 +1976,23 @@ class ModelTest extends CakeTestCase { $this->assertEqual($result[6]['Attachment'], $expected); } + function testSaveAllHasMany() { + $this->loadFixtures('Article', 'Comment'); + $this->model =& new Article(); + $this->model->belongsTo = $this->model->hasAndBelongsToMany = array(); + + $this->assertTrue($this->model->saveAll(array( + 'Article' => array('id' => 2), + 'Comment' => array( + array('comment' => 'First new comment', 'published' => 'Y', 'user_id' => 1), + array('comment' => 'Second new comment', 'published' => 'Y', 'user_id' => 2) + ) + ))); + $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); + } + function testSaveAllValidation() { $this->loadFixtures('Post', 'Author', 'Comment', 'Attachment'); $this->model =& new Post();