Skip to content

Commit

Permalink
Fixing saveAll() when used in conjunction with belongsTo data and val…
Browse files Browse the repository at this point in the history
…idate => first. Tests added.

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8010 3807eeeb-6ff5-0310-8944-8be069107fe0
  • Loading branch information
markstory committed Jan 25, 2009
1 parent af49aec commit 1895f1c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
1 change: 0 additions & 1 deletion cake/libs/model/model.php
Expand Up @@ -1513,7 +1513,6 @@ function saveAll($data = null, $options = array()) {
case 'belongsTo':
if ($this->__save($this->{$association}, $values, $options)) {
$data[$this->alias][$this->belongsTo[$association]['foreignKey']] = $this->{$association}->id;
unset($data[$association]);
} else {
$validationErrors[$association] = $this->{$association}->validationErrors;
$validates = false;
Expand Down
19 changes: 19 additions & 0 deletions cake/tests/cases/libs/model/model.test.php
Expand Up @@ -3741,6 +3741,25 @@ function testSaveAllValidateFirst() {
$this->assertIdentical(count($result), 1);
$result = Set::extract('/Comment/article_id', $result);
$this->assertTrue($result[0] === 1 || $result[0] === '1');


$model->deleteAll(true);
$data = array(
'Article' => array(
'title' => 'Post with Author saveAlled from comment',
'body' => 'This post will be saved with an author',
'user_id' => 2
),
'Comment' => array(
'comment' => 'Only new comment', 'user_id' => 2
)
);
$result = $model->Comment->saveAll($data, array('validate' => 'first'));
$this->assertTrue($result);

$result = $model->find('all');
$this->assertEqual($result[0]['Article']['title'], 'Post with Author saveAlled from comment');
$this->assertEqual($result[0]['Comment'][0]['comment'], 'Only new comment');
}
/**
* testSaveWithCounterCache method
Expand Down

0 comments on commit 1895f1c

Please sign in to comment.