avoid warning when saveAll() data has empty hasMany data, fixes #2792

This commit is contained in:
Ceeram 2012-04-16 22:46:58 +02:00
parent 9556ff714d
commit a84597784d
2 changed files with 22 additions and 0 deletions

View file

@ -2036,6 +2036,9 @@ class Model extends Object implements CakeEventListener {
if (empty($data) && $options['validate'] !== false) {
$result = $this->save($data, $options);
if (!$options['atomic']) {
return array(!empty($result));
}
return !empty($result);
}
@ -2167,6 +2170,9 @@ class Model extends Object implements CakeEventListener {
if (empty($data) && $options['validate'] !== false) {
$result = $this->save($data, $options);
if (!$options['atomic']) {
return array(!empty($result));
}
return !empty($result);
}

View file

@ -5228,6 +5228,22 @@ class ModelWriteTest extends BaseModelTest {
$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
*