Skip to content

Commit

Permalink
Making saveAll() behave like plain save() when suplied empty data arr…
Browse files Browse the repository at this point in the history
…ay, closes #277
  • Loading branch information
lorenzo committed Mar 17, 2010
1 parent 8375570 commit 5c186d4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cake/libs/model/model.php
Expand Up @@ -1584,6 +1584,11 @@ function saveAll($data = null, $options = array()) {
$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);
}
Expand Down
18 changes: 18 additions & 0 deletions cake/tests/cases/libs/model/model_write.test.php
Expand Up @@ -3798,6 +3798,24 @@ function testProductUpdateAllWithoutForeignKey() {
$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);
}

}

?>

0 comments on commit 5c186d4

Please sign in to comment.