Fixed bug in Model::__save validation logic, closes #4554

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6824 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
the_undefined 2008-05-13 01:03:11 +00:00
parent 232e3f7ec1
commit 823eb81dc7
2 changed files with 18 additions and 1 deletions

View file

@ -1428,7 +1428,7 @@ class Model extends Overloadable {
*/ */
function __save(&$model, $data, $options) { function __save(&$model, $data, $options) {
if ($options['validate'] === 'first' || $options['validate'] === 'only') { if ($options['validate'] === 'first' || $options['validate'] === 'only') {
if (!($model->create($data) && $this->validates())) { if (!($model->create($data) && $model->validates())) {
return false; return false;
} }
} elseif (!($model->create(null) !== null && $model->save($data, $options))) { } elseif (!($model->create(null) !== null && $model->save($data, $options))) {

View file

@ -2321,6 +2321,23 @@ class ModelTest extends CakeTestCase {
$this->model->validate['body'] = VALID_NOT_EMPTY; $this->model->validate['body'] = VALID_NOT_EMPTY;
} }
function testSaveAllValidationOnly() {
$this->model =& new Comment();
$this->model->Attachment->validate = array('attachment' => VALID_NOT_EMPTY);
$data = array(
'Comment' => array(
'comment' => 'This is the comment'
),
'Attachment' => array(
'attachment' => ''
)
);
$result = $this->model->saveAll($data, array('validate' => 'only'));
$this->assertFalse($result);
}
function testSaveWithCounterCache() { function testSaveWithCounterCache() {
$this->loadFixtures('Syfile', 'Item'); $this->loadFixtures('Syfile', 'Item');
$this->model =& new Syfile(); $this->model =& new Syfile();