mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-02-07 12:36:25 +00:00
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:
parent
9a6029f03e
commit
9e37b6fc26
2 changed files with 18 additions and 1 deletions
|
@ -1376,7 +1376,7 @@ class Model extends Overloadable {
|
||||||
foreach ($values as $i => $value) {
|
foreach ($values as $i => $value) {
|
||||||
$values[$i][$this->{$type}[$association]['foreignKey']] = $this->id;
|
$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;
|
$validationErrors[$association] = $this->{$association}->validationErrors;
|
||||||
$validates = false;
|
$validates = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1976,6 +1976,23 @@ class ModelTest extends CakeTestCase {
|
||||||
$this->assertEqual($result[6]['Attachment'], $expected);
|
$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() {
|
function testSaveAllValidation() {
|
||||||
$this->loadFixtures('Post', 'Author', 'Comment', 'Attachment');
|
$this->loadFixtures('Post', 'Author', 'Comment', 'Attachment');
|
||||||
$this->model =& new Post();
|
$this->model =& new Post();
|
||||||
|
|
Loading…
Add table
Reference in a new issue