Skip to content

Commit b02e213

Browse files
committed
Adding test case from '0x20h'. Fixing issue where atomic = false, validate = first and saveAll() saving many rows could return an incorrect value. Fixes #1050
1 parent ea9e308 commit b02e213

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

cake/libs/model/model.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1593,6 +1593,7 @@ function saveAll($data = null, $options = array()) {
15931593

15941594
if (Set::numeric(array_keys($data))) {
15951595
while ($validates) {
1596+
$return = array();
15961597
foreach ($data as $key => $record) {
15971598
if (!$currentValidates = $this->__save($record, $options)) {
15981599
$validationErrors[$key] = $this->validationErrors;
@@ -1624,7 +1625,6 @@ function saveAll($data = null, $options = array()) {
16241625
break;
16251626
case ($options['validate'] === 'first'):
16261627
$options['validate'] = true;
1627-
$return = array();
16281628
break;
16291629
default:
16301630
if ($options['atomic']) {

cake/tests/cases/libs/model/model_write.test.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3584,6 +3584,65 @@ function testSaveAllValidateFirst() {
35843584
$this->assertEqual($result[0]['Comment'][0]['comment'], 'Only new comment');
35853585
}
35863586

3587+
/**
3588+
* test saveAll()'s return is correct when using atomic = false and validate = first.
3589+
*
3590+
* @return void
3591+
*/
3592+
function testSaveAllValidateFirstAtomicFalse() {
3593+
$Something =& new Something();
3594+
$invalidData = array(
3595+
array(
3596+
'title' => 'foo',
3597+
'body' => 'bar',
3598+
'published' => 'baz',
3599+
),
3600+
array(
3601+
'body' => 3,
3602+
'published' =>'sd',
3603+
),
3604+
);
3605+
$Something->create();
3606+
$Something->validate = array(
3607+
'title' => array(
3608+
'rule' => 'alphaNumeric',
3609+
'required' => true,
3610+
),
3611+
'body' => array(
3612+
'rule' => 'alphaNumeric',
3613+
'required' => true,
3614+
'allowEmpty' => true,
3615+
),
3616+
);
3617+
$result = $Something->saveAll($invalidData, array(
3618+
'atomic' => false,
3619+
'validate' => 'first',
3620+
));
3621+
$expected = array(true, false);
3622+
$this->assertEqual($result, $expected);
3623+
3624+
$Something =& new Something();
3625+
$validData = array(
3626+
array(
3627+
'title' => 'title value',
3628+
'body' => 'body value',
3629+
'published' => 'baz',
3630+
),
3631+
array(
3632+
'title' => 'valid',
3633+
'body' => 'this body',
3634+
'published' =>'sd',
3635+
),
3636+
);
3637+
$Something->create();
3638+
$result = $Something->saveAll($validData, array(
3639+
'atomic' => false,
3640+
'validate' => 'first',
3641+
));
3642+
$expected = array(true, true);
3643+
$this->assertEqual($result, $expected);
3644+
}
3645+
35873646
/**
35883647
* testUpdateWithCalculation method
35893648
*

0 commit comments

Comments
 (0)