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
This commit is contained in:
nate 2008-03-09 07:59:23 +00:00
parent 9a6029f03e
commit 9e37b6fc26
2 changed files with 18 additions and 1 deletions

View file

@ -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;
}

View file

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