Skip to content

Commit 65efd67

Browse files
committed
Fixing fatal error caused by associated models using a datasource that is not a subclass of dbo_source. Test added. Fixes #873
1 parent 1033461 commit 65efd67

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

cake/libs/model/datasources/dbo_source.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,7 @@ function read(&$model, $queryData = array(), $recursive = null) {
841841
$db =& $this;
842842
}
843843

844-
if (isset($db)) {
844+
if (isset($db) && method_exists($db, 'queryAssociation')) {
845845
$stack = array($assoc);
846846
$db->queryAssociation($model, $linkModel, $type, $assoc, $assocData, $array, true, $resultSet, $model->recursive - 1, $stack);
847847
unset($db);

cake/tests/cases/libs/model/datasources/dbo_source.test.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,6 +1339,7 @@ function getLastQuery() {
13391339
function endTest() {
13401340
unset($this->Model);
13411341
Configure::write('debug', $this->debug);
1342+
ClassRegistry::flush();
13421343
unset($this->debug);
13431344
}
13441345

@@ -4441,4 +4442,19 @@ function testFullTablePermutations() {
44414442
$result = $this->testDb->fullTableName($Article, false);
44424443
$this->assertEqual($result, 'tbl_articles');
44434444
}
4445+
4446+
/**
4447+
* test that read() only calls queryAssociation on db objects when the method is defined.
4448+
*
4449+
* @return void
4450+
*/
4451+
function testReadOnlyCallingQueryAssociationWhenDefined() {
4452+
ConnectionManager::create('test_no_queryAssociation', array(
4453+
'datasource' => 'data'
4454+
));
4455+
$Article =& ClassRegistry::init('Article');
4456+
$Article->Comment->useDbConfig = 'test_no_queryAssociation';
4457+
$result = $Article->find('all');
4458+
$this->assertTrue(is_array($result));
4459+
}
44444460
}

0 commit comments

Comments
 (0)