Skip to content

Commit a845977

Browse files
committed
avoid warning when saveAll() data has empty hasMany data, fixes #2792
1 parent 9556ff7 commit a845977

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

lib/Cake/Model/Model.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2036,6 +2036,9 @@ public function saveMany($data = null, $options = array()) {
20362036

20372037
if (empty($data) && $options['validate'] !== false) {
20382038
$result = $this->save($data, $options);
2039+
if (!$options['atomic']) {
2040+
return array(!empty($result));
2041+
}
20392042
return !empty($result);
20402043
}
20412044

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

21682171
if (empty($data) && $options['validate'] !== false) {
21692172
$result = $this->save($data, $options);
2173+
if (!$options['atomic']) {
2174+
return array(!empty($result));
2175+
}
21702176
return !empty($result);
21712177
}
21722178

lib/Cake/Test/Case/Model/ModelWriteTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5228,6 +5228,22 @@ public function testSaveAssociatedHasMany() {
52285228
$this->assertEquals($expected, Set::extract($result['Comment'], '{n}.comment'));
52295229
}
52305230

5231+
/**
5232+
* testSaveAssociatedHasManyEmpty method
5233+
*
5234+
* @return void
5235+
*/
5236+
public function testSaveAssociatedHasManyEmpty() {
5237+
$this->loadFixtures('Article', 'Comment');
5238+
$TestModel = new Article();
5239+
$TestModel->belongsTo = $TestModel->hasAndBelongsToMany = array();
5240+
$result = $TestModel->saveAssociated(array(
5241+
'Article' => array('title' => 'title', 'author_id' => 1),
5242+
'Comment' => array()
5243+
), array('validate' => true));
5244+
$this->assertTrue($result);
5245+
}
5246+
52315247
/**
52325248
* testSaveAssociatedHasManyValidation method
52335249
*

0 commit comments

Comments
 (0)