Fxiing validation error when trying to update records using saveAll for hasMany fixes #4981

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7506 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
DarkAngelBGE 2008-08-26 13:31:07 +00:00
parent 59efe5c445
commit 285d075475
2 changed files with 10 additions and 11 deletions

View file

@ -1313,11 +1313,7 @@ class Model extends Overloadable {
while ($validates) { while ($validates) {
foreach ($data as $key => $record) { foreach ($data as $key => $record) {
if (!$validates = $this->__save($this, $record, $options)) { if (!$validates = $this->__save($this, $record, $options)) {
if (empty($this->id)) { $validationErrors[$key] = $this->validationErrors;
$validationErrors[$key] = $this->validationErrors;
} else {
$validationErrors[$this->id] = $this->validationErrors;
}
} }
$validating = ($options['validate'] === 'only' || $options['validate'] === 'first'); $validating = ($options['validate'] === 'only' || $options['validate'] === 'first');

View file

@ -3077,7 +3077,7 @@ class ModelTest extends CakeTestCase {
$this->assertEqual($result, false); $this->assertEqual($result, false);
$result = $TestModel->find('all', array('recursive' => -1)); $result = $TestModel->find('all', array('recursive' => -1));
$errors = array(2 => array('title' => 'This field cannot be left blank')); $errors = array(1 => array('title' => 'This field cannot be left blank'));
$transactionWorked = Set::matches('/Post[1][title=Baleeted First Post]', $result); $transactionWorked = Set::matches('/Post[1][title=Baleeted First Post]', $result);
if (!$transactionWorked) { if (!$transactionWorked) {
$this->assertTrue(Set::matches('/Post[1][title=Un-Baleeted First Post]', $result)); $this->assertTrue(Set::matches('/Post[1][title=Un-Baleeted First Post]', $result));
@ -3094,7 +3094,7 @@ class ModelTest extends CakeTestCase {
$result = $TestModel->saveAll($data, array('atomic' => false)); $result = $TestModel->saveAll($data, array('atomic' => false));
$this->assertEqual($result, array(true, false)); $this->assertEqual($result, array(true, false));
$result = $TestModel->find('all', array('recursive' => -1)); $result = $TestModel->find('all', array('recursive' => -1));
$errors = array(2 => array('title' => 'This field cannot be left blank')); $errors = array(1 => array('title' => 'This field cannot be left blank'));
$newTs = date('Y-m-d H:i:s'); $newTs = date('Y-m-d H:i:s');
$expected = array( $expected = array(
array('Post' => array('id' => '1', 'author_id' => '1', 'title' => 'Un-Baleeted First Post', 'body' => 'Not Baleeted!', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => $newTs)), array('Post' => array('id' => '1', 'author_id' => '1', 'title' => 'Un-Baleeted First Post', 'body' => 'Not Baleeted!', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => $newTs)),
@ -5532,7 +5532,7 @@ class ModelTest extends CakeTestCase {
), ),
array('validate' => 'only') array('validate' => 'only')
); );
$this->assertIdentical($result, false); $this->assertFalse($result);
$result = $TestModel->saveAll( $result = $TestModel->saveAll(
array( array(
@ -5540,20 +5540,23 @@ class ModelTest extends CakeTestCase {
'Comment' => array( 'Comment' => array(
array('id' => 1, 'comment' => '', 'published' => 'Y', 'user_id' => 1), array('id' => 1, 'comment' => '', 'published' => 'Y', 'user_id' => 1),
array('id' => 2, 'comment' => 'comment', 'published' => 'Y', 'user_id' => 1), array('id' => 2, 'comment' => 'comment', 'published' => 'Y', 'user_id' => 1),
array('id' => 3, 'comment' => '', 'published' => 'Y', 'user_id' => 1),
) )
), ),
array('validate' => 'only', 'atomic' => false) array('validate' => 'only', 'atomic' => false)
); );
$expected = array('Article' => true, 'Comment' => array(false, true)); $expected = array('Article' => true, 'Comment' => array(false, true, false));
$this->assertIdentical($result, $expected); $this->assertIdentical($result, $expected);
$expected = array('Comment' => array( $expected = array('Comment' => array(
1 => array('comment' => 'This field cannot be left blank') 0 => array('comment' => 'This field cannot be left blank'),
2 => array('comment' => 'This field cannot be left blank')
)); ));
$this->assertEqual($TestModel->validationErrors, $expected); $this->assertEqual($TestModel->validationErrors, $expected);
$expected = array( $expected = array(
1 => array('comment' => 'This field cannot be left blank') 0 => array('comment' => 'This field cannot be left blank'),
2 => array('comment' => 'This field cannot be left blank')
); );
$this->assertEqual($TestModel->Comment->validationErrors, $expected); $this->assertEqual($TestModel->Comment->validationErrors, $expected);
} }