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:
nate 2008-05-16 06:03:33 +00:00
parent 0f1e075d68
commit d9a7170808
2 changed files with 41 additions and 2 deletions

View file

@ -1310,9 +1310,11 @@ class Model extends Overloadable {
$validationErrors[$this->id] = $this->validationErrors;
}
}
$validating = ($options['validate'] === 'only' || $options['validate'] === 'first');
if (!$options['atomic']) {
$return[] = $validates;
} elseif (!$validates) {
} elseif (!$validates && !$validating) {
break;
}
}
@ -1367,8 +1369,10 @@ class Model extends Overloadable {
if (!$options['atomic']) {
$return[$this->alias][] = $validates;
}
$validating = ($options['validate'] === 'only' || $options['validate'] === 'first');
foreach ($data as $association => $values) {
if (!$validates) {
if (!$validates && !$validating) {
break;
}
if (isset($associations[$association])) {

View file

@ -2182,6 +2182,41 @@ class ModelTest extends CakeTestCase {
$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() {
$this->loadFixtures('Article', 'User');
$TestModel =& new Article();