Merge pull request #7242 from tanuck/2.7-no-table-validation-fail

2.7 fix PDO exception from Model::exists when useTable is false - #7229
This commit is contained in:
Mark Story 2015-08-18 22:30:15 -04:00
commit daa795dfd3
4 changed files with 44 additions and 11 deletions

View file

@ -2895,6 +2895,10 @@ class Model extends Object implements CakeEventListener {
return false;
}
if ($this->useTable === false) {
return false;
}
return (bool)$this->find('count', array(
'conditions' => array(
$this->alias . '.' . $this->primaryKey => $id

View file

@ -1334,7 +1334,7 @@ class ModelIntegrationTest extends BaseModelTest {
$Article->useTable = false;
$Article->id = 1;
$result = $Article->exists();
$this->assertTrue($result);
$this->assertFalse($result);
}
/**

View file

@ -554,6 +554,44 @@ class ModelValidationTest extends BaseModelTest {
$this->assertEquals($expected, $result);
}
/**
* test that validates() still performs correctly when useTable = false on the model.
*
* @return void
*/
public function testValidatesWithNoTable() {
$TestModel = new TheVoid();
$TestModel->validate = array(
'title' => array(
'notEmpty' => array(
'rule' => array('notBlank'),
'required' => true,
),
'tooShort' => array(
'rule' => array('minLength', 10),
),
),
);
$data = array(
'TheVoid' => array(
'title' => 'too short',
),
);
$TestModel->create($data);
$result = $TestModel->validates();
$this->assertFalse($result);
$data = array(
'TheVoid' => array(
'id' => '1',
'title' => 'A good title',
),
);
$TestModel->create($data);
$result = $TestModel->validates();
$this->assertTrue($result);
}
/**
* test that validates() checks all the 'with' associations as well for validation
* as this can cause partial/wrong data insertion.

View file

@ -2785,18 +2785,9 @@ class ModelWriteTest extends BaseModelTest {
$TestModel = new TheVoid();
$this->assertFalse($TestModel->exists());
}
/**
* testRecordExistsMissingTable method
*
* @expectedException PDOException
* @return void
*/
public function testRecordExistsMissingTable() {
$TestModel = new TheVoid();
$TestModel->id = 5;
$TestModel->exists();
$this->assertFalse($TestModel->exists());
}
/**