diff --git a/cake/libs/model/model.php b/cake/libs/model/model.php index f8ccaf81d..3c900e3a6 100644 --- a/cake/libs/model/model.php +++ b/cake/libs/model/model.php @@ -1584,6 +1584,11 @@ class Model extends Overloadable { $validates = true; $return = array(); + if (empty($data) && $options['validate'] !== false) { + $result = $this->save($data, $options); + return !empty($result); + } + if ($options['atomic'] && $options['validate'] !== 'only') { $db->begin($this); } diff --git a/cake/tests/cases/libs/model/model_write.test.php b/cake/tests/cases/libs/model/model_write.test.php index 22f878443..3b27a079b 100644 --- a/cake/tests/cases/libs/model/model_write.test.php +++ b/cake/tests/cases/libs/model/model_write.test.php @@ -3798,6 +3798,24 @@ class ModelWriteTest extends BaseModelTest { $this->assertEqual($resultsFkFalse, $expected); } +/** + * test that saveAll behaves like plain save() when suplied empty data + * + * @link http://cakephp.lighthouseapp.com/projects/42648/tickets/277-test-saveall-with-validation-returns-incorrect-boolean-when-saving-empty-data + * @access public + * @return void + */ + function testSaveAllEmptyData() { + $this->loadFixtures('Article', 'ProductUpdateAll'); + $model =& new Article(); + $result = $model->saveAll(array(), array('validate' => 'first')); + $this->assertTrue($result); + + $model =& new ProductUpdateAll(); + $result = $model->saveAll(array()); + $this->assertFalse($result); + } + } ?> \ No newline at end of file