Merge branch 'saveAll' into 1.3

* saveAll:
  Making saveAll() behave like plain save() when suplied empty data array, closes #277
This commit is contained in:
José Lorenzo Rodríguez 2010-03-17 16:40:26 -04:30
commit 0f876e1a1b
2 changed files with 23 additions and 0 deletions

View file

@ -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);
}

View file

@ -3807,6 +3807,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);
}
}
?>