mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Changed default value for option 'validate' to 'first' in Model::saveAll(). Also fixed issue where the return array contained more keys then number of records in data array itself with options 'validate =>'first' and 'atomic'=>false
This commit is contained in:
parent
7b28fdec85
commit
d365fafe4d
2 changed files with 11 additions and 8 deletions
|
@ -1556,9 +1556,9 @@ class Model extends Overloadable {
|
||||||
*
|
*
|
||||||
* #### Options
|
* #### Options
|
||||||
*
|
*
|
||||||
* - validate: Set to false to disable validation, true to validate each record before
|
* - validate: Set to false to disable validation, true to validate each record before saving,
|
||||||
* saving, 'first' to validate *all* records before any are saved, or 'only' to only
|
* 'first' to validate *all* records before any are saved (default),
|
||||||
* validate the records, but not save them.
|
* or 'only' to only validate the records, but not save them.
|
||||||
* - atomic: If true (default), will attempt to save all records in a single transaction.
|
* - atomic: If true (default), will attempt to save all records in a single transaction.
|
||||||
* Should be set to false if database/table does not support transactions.
|
* Should be set to false if database/table does not support transactions.
|
||||||
* - fieldList: Equivalent to the $fieldList parameter in Model::save()
|
* - fieldList: Equivalent to the $fieldList parameter in Model::save()
|
||||||
|
@ -1579,7 +1579,7 @@ class Model extends Overloadable {
|
||||||
}
|
}
|
||||||
$db =& ConnectionManager::getDataSource($this->useDbConfig);
|
$db =& ConnectionManager::getDataSource($this->useDbConfig);
|
||||||
|
|
||||||
$options = array_merge(array('validate' => true, 'atomic' => true), $options);
|
$options = array_merge(array('validate' => 'first', 'atomic' => true), $options);
|
||||||
$this->validationErrors = $validationErrors = array();
|
$this->validationErrors = $validationErrors = array();
|
||||||
$validates = true;
|
$validates = true;
|
||||||
$return = array();
|
$return = array();
|
||||||
|
@ -1626,6 +1626,7 @@ class Model extends Overloadable {
|
||||||
break;
|
break;
|
||||||
case ($options['validate'] === 'first'):
|
case ($options['validate'] === 'first'):
|
||||||
$options['validate'] = true;
|
$options['validate'] = true;
|
||||||
|
$return = array();
|
||||||
continue;
|
continue;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -1731,6 +1732,7 @@ class Model extends Overloadable {
|
||||||
break;
|
break;
|
||||||
case ($options['validate'] === 'first'):
|
case ($options['validate'] === 'first'):
|
||||||
$options['validate'] = true;
|
$options['validate'] = true;
|
||||||
|
$return = array();
|
||||||
continue;
|
continue;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -2871,7 +2871,8 @@ class ModelWriteTest extends BaseModelTest {
|
||||||
'title' => '',
|
'title' => '',
|
||||||
'body' => 'Trying to get away with an empty title'
|
'body' => 'Trying to get away with an empty title'
|
||||||
)
|
)
|
||||||
), array('atomic' => false));
|
), array('validate' => true, 'atomic' => false));
|
||||||
|
|
||||||
$this->assertIdentical($result, array(true, false));
|
$this->assertIdentical($result, array(true, false));
|
||||||
|
|
||||||
$result = $TestModel->saveAll(array(
|
$result = $TestModel->saveAll(array(
|
||||||
|
@ -2887,7 +2888,7 @@ class ModelWriteTest extends BaseModelTest {
|
||||||
'published' => 'Y',
|
'published' => 'Y',
|
||||||
'user_id' => 2
|
'user_id' => 2
|
||||||
))
|
))
|
||||||
), array('atomic' => false));
|
), array('validate' => true, 'atomic' => false));
|
||||||
$this->assertIdentical($result, array('Article' => true, 'Comment' => array(true, true)));
|
$this->assertIdentical($result, array('Article' => true, 'Comment' => array(true, true)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2985,7 +2986,7 @@ class ModelWriteTest extends BaseModelTest {
|
||||||
'Comment' => array(
|
'Comment' => array(
|
||||||
array('comment' => '', 'published' => 'Y', 'user_id' => 1),
|
array('comment' => '', 'published' => 'Y', 'user_id' => 1),
|
||||||
)
|
)
|
||||||
));
|
), array('validate' => true));
|
||||||
$expected = array('Comment' => array(false));
|
$expected = array('Comment' => array(false));
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
|
@ -3318,7 +3319,7 @@ class ModelWriteTest extends BaseModelTest {
|
||||||
'title' => '',
|
'title' => '',
|
||||||
'body' => 'Trying to get away with an empty title'
|
'body' => 'Trying to get away with an empty title'
|
||||||
));
|
));
|
||||||
$result = $TestModel->saveAll($data, array('atomic' => false));
|
$result = $TestModel->saveAll($data, array('validate' => true, 'atomic' => false));
|
||||||
$this->assertEqual($result, array(true, false));
|
$this->assertEqual($result, array(true, false));
|
||||||
$result = $TestModel->find('all', array('recursive' => -1, 'order' => 'Post.id ASC'));
|
$result = $TestModel->find('all', array('recursive' => -1, 'order' => 'Post.id ASC'));
|
||||||
$errors = array(1 => array('title' => 'This field cannot be left blank'));
|
$errors = array(1 => array('title' => 'This field cannot be left blank'));
|
||||||
|
|
Loading…
Reference in a new issue