mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 02:26:17 +00:00
Adding validation message fixes for Model::saveAll() and hasOne associations, fixes #4561
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6898 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
0f1e075d68
commit
d9a7170808
2 changed files with 41 additions and 2 deletions
|
@ -1310,9 +1310,11 @@ class Model extends Overloadable {
|
||||||
$validationErrors[$this->id] = $this->validationErrors;
|
$validationErrors[$this->id] = $this->validationErrors;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$validating = ($options['validate'] === 'only' || $options['validate'] === 'first');
|
||||||
|
|
||||||
if (!$options['atomic']) {
|
if (!$options['atomic']) {
|
||||||
$return[] = $validates;
|
$return[] = $validates;
|
||||||
} elseif (!$validates) {
|
} elseif (!$validates && !$validating) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1367,8 +1369,10 @@ class Model extends Overloadable {
|
||||||
if (!$options['atomic']) {
|
if (!$options['atomic']) {
|
||||||
$return[$this->alias][] = $validates;
|
$return[$this->alias][] = $validates;
|
||||||
}
|
}
|
||||||
|
$validating = ($options['validate'] === 'only' || $options['validate'] === 'first');
|
||||||
|
|
||||||
foreach ($data as $association => $values) {
|
foreach ($data as $association => $values) {
|
||||||
if (!$validates) {
|
if (!$validates && !$validating) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (isset($associations[$association])) {
|
if (isset($associations[$association])) {
|
||||||
|
|
|
@ -2182,6 +2182,41 @@ class ModelTest extends CakeTestCase {
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testSaveAllHasOneValidation() {
|
||||||
|
$model = new Comment();
|
||||||
|
$model->deleteAll(true);
|
||||||
|
$this->assertEqual($model->find('all'), array());
|
||||||
|
|
||||||
|
$model->Attachment->deleteAll(true);
|
||||||
|
$this->assertEqual($model->Attachment->find('all'), array());
|
||||||
|
|
||||||
|
$model->validate = array('comment' => VALID_NOT_EMPTY);
|
||||||
|
$model->Attachment->validate = array('attachment' => VALID_NOT_EMPTY);
|
||||||
|
$model->Attachment->bind('Comment');
|
||||||
|
|
||||||
|
$this->assertFalse($model->saveAll(
|
||||||
|
array(
|
||||||
|
'Comment' => array('comment' => '', 'article_id' => 1, 'user_id' => 1),
|
||||||
|
'Attachment' => array('attachment' => '')
|
||||||
|
),
|
||||||
|
array('validate' => 'first')
|
||||||
|
));
|
||||||
|
$expected = array(
|
||||||
|
'Comment' => array('comment' => 'This field cannot be left blank'),
|
||||||
|
'Attachment' => array('attachment' => 'This field cannot be left blank')
|
||||||
|
);
|
||||||
|
$this->assertEqual($model->validationErrors, $expected);
|
||||||
|
|
||||||
|
$this->assertFalse($model->saveAll(
|
||||||
|
array(
|
||||||
|
'Comment' => array('comment' => '', 'article_id' => 1, 'user_id' => 1),
|
||||||
|
'Attachment' => array('attachment' => '')
|
||||||
|
),
|
||||||
|
array('validate' => 'only')
|
||||||
|
));
|
||||||
|
$this->assertEqual($model->validationErrors, $expected);
|
||||||
|
}
|
||||||
|
|
||||||
function testSaveAllAtomic() {
|
function testSaveAllAtomic() {
|
||||||
$this->loadFixtures('Article', 'User');
|
$this->loadFixtures('Article', 'User');
|
||||||
$TestModel =& new Article();
|
$TestModel =& new Article();
|
||||||
|
|
Loading…
Add table
Reference in a new issue