Skip to content

Commit

Permalink
avoid warning when saveAll() data has empty hasMany data, fixes #2792
Browse files Browse the repository at this point in the history
  • Loading branch information
ceeram committed Apr 16, 2012
1 parent 9556ff7 commit a845977
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/Cake/Model/Model.php
Expand Up @@ -2036,6 +2036,9 @@ public function saveMany($data = null, $options = array()) {

if (empty($data) && $options['validate'] !== false) {
$result = $this->save($data, $options);
if (!$options['atomic']) {
return array(!empty($result));
}
return !empty($result);
}

Expand Down Expand Up @@ -2167,6 +2170,9 @@ public function saveAssociated($data = null, $options = array()) {

if (empty($data) && $options['validate'] !== false) {
$result = $this->save($data, $options);
if (!$options['atomic']) {
return array(!empty($result));
}
return !empty($result);
}

Expand Down
16 changes: 16 additions & 0 deletions lib/Cake/Test/Case/Model/ModelWriteTest.php
Expand Up @@ -5228,6 +5228,22 @@ public function testSaveAssociatedHasMany() {
$this->assertEquals($expected, Set::extract($result['Comment'], '{n}.comment'));
}

/**
* testSaveAssociatedHasManyEmpty method
*
* @return void
*/
public function testSaveAssociatedHasManyEmpty() {
$this->loadFixtures('Article', 'Comment');
$TestModel = new Article();
$TestModel->belongsTo = $TestModel->hasAndBelongsToMany = array();
$result = $TestModel->saveAssociated(array(
'Article' => array('title' => 'title', 'author_id' => 1),
'Comment' => array()
), array('validate' => true));
$this->assertTrue($result);
}

/**
* testSaveAssociatedHasManyValidation method
*
Expand Down

0 comments on commit a845977

Please sign in to comment.