diff --git a/cake/libs/model/db_acl.php b/cake/libs/model/db_acl.php index af58e473d..5ab4c9168 100644 --- a/cake/libs/model/db_acl.php +++ b/cake/libs/model/db_acl.php @@ -117,7 +117,7 @@ class AclNode extends AppModel { 'conditions' => array( $db->name("{$type}{$i}.lft") . ' > ' . $db->name("{$type}{$j}.lft"), $db->name("{$type}{$i}.rght") . ' < ' . $db->name("{$type}{$j}.rght"), - $db->name("{$type}{$i}.alias") . ' = ' . $db->value($alias) + $db->name("{$type}{$i}.alias") . ' = ' . $db->value($alias, 'string') ) ); diff --git a/cake/libs/model/model.php b/cake/libs/model/model.php index 972f51995..f22559a51 100644 --- a/cake/libs/model/model.php +++ b/cake/libs/model/model.php @@ -1350,7 +1350,7 @@ class Model extends Overloadable { switch (true) { case ($options['validate'] === 'only'): - return $validates; + return ($options['atomic'] ? $validates : $return); break; case ($options['validate'] === 'first'): $options['validate'] = true; @@ -1395,7 +1395,7 @@ class Model extends Overloadable { $validates = false; } if (!$options['atomic']) { - $return[$this->alias][] = $validates; + $return[$this->alias] = $validates; } $validating = ($options['validate'] === 'only' || $options['validate'] === 'first'); @@ -1447,15 +1447,15 @@ class Model extends Overloadable { } } } - $this->validationErrors = $validationErrors; + if (isset($validationErrors[$this->alias])) { $this->validationErrors = $validationErrors[$this->alias]; } switch (true) { case ($options['validate'] === 'only'): - return $validates; + return ($options['atomic'] ? $validates : $return); break; case ($options['validate'] === 'first'): $options['validate'] = true; diff --git a/cake/tests/cases/libs/model/model.test.php b/cake/tests/cases/libs/model/model.test.php index a029337ba..ca0edaab2 100644 --- a/cake/tests/cases/libs/model/model.test.php +++ b/cake/tests/cases/libs/model/model.test.php @@ -2730,7 +2730,7 @@ class ModelTest extends CakeTestCase { 'Article' => array('title' => 'Post with Author', 'body' => 'This post will be saved with an author', 'user_id' => 2), 'Comment' => array(array('comment' => 'First new comment', 'user_id' => 2)) ), array('atomic' => false)); - $this->assertIdentical($result, array('Article' => array(true), 'Comment' => array(true))); + $this->assertIdentical($result, array('Article' => true, 'Comment' => array(true))); $result = $TestModel->saveAll(array( array('id' => '1', 'title' => 'Baleeted First Post', 'body' => 'Baleeted!', 'published' => 'N'), @@ -2753,7 +2753,7 @@ class ModelTest extends CakeTestCase { array('comment' => 'Second new comment', 'published' => 'Y', 'user_id' => 2) ) ), array('atomic' => false)); - $this->assertIdentical($result, array('Article' => array(true), 'Comment' => array(true, true))); + $this->assertIdentical($result, array('Article' => true, 'Comment' => array(true, true))); } /** * testSaveAllHasMany method @@ -2804,7 +2804,7 @@ class ModelTest extends CakeTestCase { ), array('atomic' => false) ); - $this->assertEqual($result, array('Article' => array(0 => false))); + $this->assertEqual($result, array('Article' => false)); $result = $TestModel->findById(2); $expected = array('First Comment for Second Article', 'Second Comment for Second Article', 'First new comment', 'Second new comment', 'Third new comment'); @@ -5129,6 +5129,53 @@ class ModelTest extends CakeTestCase { $this->assertTrue(is_array($result)); $this->assertEqual($result, $expected); } +/** + * testSaveAllHasManyValidationOnly method + * + * @access public + * @return void + */ + function testSaveAllHasManyValidationOnly() { + $this->loadFixtures('Article', 'Comment'); + $TestModel =& new Article(); + $TestModel->belongsTo = $TestModel->hasAndBelongsToMany = array(); + $TestModel->Comment->validate = array('comment' => VALID_NOT_EMPTY); + + $result = $TestModel->saveAll( + array( + 'Article' => array('id' => 2), + 'Comment' => array( + array('id' => 1, 'comment' => '', 'published' => 'Y', 'user_id' => 1), + array('id' => 2, 'comment' => 'comment', 'published' => 'Y', 'user_id' => 1), + ) + ), + array('validate' => 'only') + ); + $this->assertIdentical($result, false); + + $result = $TestModel->saveAll( + array( + 'Article' => array('id' => 2), + 'Comment' => array( + array('id' => 1, 'comment' => '', 'published' => 'Y', 'user_id' => 1), + array('id' => 2, 'comment' => 'comment', 'published' => 'Y', 'user_id' => 1), + ) + ), + array('validate' => 'only', 'atomic' => false) + ); + $expected = array('Article' => true, 'Comment' => array(false, true)); + $this->assertIdentical($result, $expected); + + $expected = array('Comment' => array( + 1 => array('comment' => 'This field cannot be left blank') + )); + $this->assertEqual($TestModel->validationErrors, $expected); + + $expected = array( + 1 => array('comment' => 'This field cannot be left blank') + ); + $this->assertEqual($TestModel->Comment->validationErrors, $expected); + } /** * endTest method * @@ -5140,4 +5187,4 @@ class ModelTest extends CakeTestCase { } } -?> +?> \ No newline at end of file