Skip to content

Commit

Permalink
comp mod for saveAll()
Browse files Browse the repository at this point in the history
better approach

test case to assert saveAll still behaves like previous versions
  • Loading branch information
euromark committed Oct 11, 2012
1 parent 2e15689 commit 1e2ac0b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/Cake/Model/Model.php
Expand Up @@ -2017,7 +2017,7 @@ protected function _prepareUpdateFields($data) {
* @link http://book.cakephp.org/2.0/en/models/saving-your-data.html#model-saveassociated-array-data-null-array-options-array
* @link http://book.cakephp.org/2.0/en/models/saving-your-data.html#model-saveall-array-data-null-array-options-array
*/
public function saveAll($data, $options = array()) {
public function saveAll($data = array(), $options = array()) {
$options = array_merge(array('validate' => 'first'), $options);
if (Hash::numeric(array_keys($data))) {
if ($options['validate'] === 'only') {
Expand Down
28 changes: 27 additions & 1 deletion lib/Cake/Test/Case/Model/ModelWriteTest.php
Expand Up @@ -4725,6 +4725,32 @@ public function testSaveAllHasManyValidationOnly() {
$this->assertEquals($expected, $TestModel->Comment->validationErrors);
}

/**
* test that saveAll still behaves like previous versions (does not necessarily need a first argument)
*
* @return void
*/
public function testSaveAllWithSet() {
$this->loadFixtures('Article', 'Tag', 'Comment', 'User', 'ArticlesTag');
$data = array(
'Article' => array(
'user_id' => 1,
'title' => 'Article Has and belongs to Many Tags'
),
'Tag' => array(
'Tag' => array(1, 2)
),
'Comment' => array(
array(
'comment' => 'Article comment',
'user_id' => 1
)));
$Article = new Article();
$Article->set($data);
$result = $Article->saveAll();
$this->assertFalse(empty($result));
}

/**
* test that saveAll behaves like plain save() when supplied empty data
*
Expand All @@ -4740,7 +4766,7 @@ public function testSaveAllEmptyData() {
$this->assertFalse(empty($result));

$model = new ProductUpdateAll();
$result = $model->saveAll(array());
$result = $model->saveAll();
$this->assertFalse($result);
}

Expand Down

0 comments on commit 1e2ac0b

Please sign in to comment.