Fixing fatal error caused by associated models using a datasource that is not a subclass of dbo_source. Test added. Fixes #873

This commit is contained in:
mark_story 2010-07-11 13:06:33 -04:00
parent 103346155f
commit 65efd675c1
2 changed files with 17 additions and 1 deletions

View file

@ -841,7 +841,7 @@ class DboSource extends DataSource {
$db =& $this;
}
if (isset($db)) {
if (isset($db) && method_exists($db, 'queryAssociation')) {
$stack = array($assoc);
$db->queryAssociation($model, $linkModel, $type, $assoc, $assocData, $array, true, $resultSet, $model->recursive - 1, $stack);
unset($db);

View file

@ -1339,6 +1339,7 @@ class DboSourceTest extends CakeTestCase {
function endTest() {
unset($this->Model);
Configure::write('debug', $this->debug);
ClassRegistry::flush();
unset($this->debug);
}
@ -4441,4 +4442,19 @@ class DboSourceTest extends CakeTestCase {
$result = $this->testDb->fullTableName($Article, false);
$this->assertEqual($result, 'tbl_articles');
}
/**
* test that read() only calls queryAssociation on db objects when the method is defined.
*
* @return void
*/
function testReadOnlyCallingQueryAssociationWhenDefined() {
ConnectionManager::create('test_no_queryAssociation', array(
'datasource' => 'data'
));
$Article =& ClassRegistry::init('Article');
$Article->Comment->useDbConfig = 'test_no_queryAssociation';
$result = $Article->find('all');
$this->assertTrue(is_array($result));
}
}