Skip to content

Commit

Permalink
Added fix for #3873
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Jul 27, 2014
1 parent d4fabc9 commit 0d66b61
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/ORM/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -1199,7 +1199,7 @@ protected function _processSave($entity, $options) {
$this,
$entity,
$options['associated'],
$options->getArrayCopy()
['validate' => (bool)$validate] + $options->getArrayCopy()
);
if ($success || !$options['atomic']) {
$entity->clean();
Expand Down
14 changes: 13 additions & 1 deletion tests/TestCase/ORM/TableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2136,17 +2136,29 @@ public function testSaveWithDifferentValidatorAndAssociations() {
'body' => 'bar',
'author' => new \Cake\ORM\Entity([
'name' => 'Susan'
])
]),
'articles_tags' => [
new \Cake\ORM\Entity([
'tag_id' => 100
])
]
]);
$table = TableRegistry::get('articles');
$table->belongsTo('authors');
$table->hasMany('ArticlesTags');
$validator = (new Validator)->validatePresence('body');
$table->validator('custom', $validator);

$validator2 = (new Validator)->validatePresence('thing');
$table->authors->validator('default', $validator2);
$this->assertFalse($table->save($entity, ['validate' => 'custom']), 'default was not used');
$this->assertNotEmpty($entity->author->errors('thing'));

$validator3 = (new Validator)->validatePresence('thing');
$table->ArticlesTags->validator('default', $validator2);
unset($entity->author);
$this->assertFalse($table->save($entity, ['validate' => 'custom']), 'default was not used');
$this->assertNotEmpty($entity->articles_tags[0]->errors('thing'));
}

/**
Expand Down

0 comments on commit 0d66b61

Please sign in to comment.