Skip to content

Commit

Permalink
Fixing fatal error caused by associated models using a datasource tha…
Browse files Browse the repository at this point in the history
…t is not a subclass of dbo_source. Test added. Fixes #873
  • Loading branch information
markstory committed Jul 11, 2010
1 parent 1033461 commit 65efd67
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cake/libs/model/datasources/dbo_source.php
Expand Up @@ -841,7 +841,7 @@ function read(&$model, $queryData = array(), $recursive = null) {
$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);
Expand Down
16 changes: 16 additions & 0 deletions cake/tests/cases/libs/model/datasources/dbo_source.test.php
Expand Up @@ -1339,6 +1339,7 @@ function getLastQuery() {
function endTest() {
unset($this->Model);
Configure::write('debug', $this->debug);
ClassRegistry::flush();
unset($this->debug);
}

Expand Down Expand Up @@ -4441,4 +4442,19 @@ function testFullTablePermutations() {
$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));
}
}

0 comments on commit 65efd67

Please sign in to comment.