From a84597784d184c782f53e77abf6b85cf90ca85a6 Mon Sep 17 00:00:00 2001 From: Ceeram Date: Mon, 16 Apr 2012 22:46:58 +0200 Subject: [PATCH] avoid warning when saveAll() data has empty hasMany data, fixes #2792 --- lib/Cake/Model/Model.php | 6 ++++++ lib/Cake/Test/Case/Model/ModelWriteTest.php | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/lib/Cake/Model/Model.php b/lib/Cake/Model/Model.php index ff74775a1..36e22d247 100644 --- a/lib/Cake/Model/Model.php +++ b/lib/Cake/Model/Model.php @@ -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); } diff --git a/lib/Cake/Test/Case/Model/ModelWriteTest.php b/lib/Cake/Test/Case/Model/ModelWriteTest.php index 994e94481..63d409947 100644 --- a/lib/Cake/Test/Case/Model/ModelWriteTest.php +++ b/lib/Cake/Test/Case/Model/ModelWriteTest.php @@ -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 *