From 65efd675c1a471d644add491cb96565ed74b3e36 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 11 Jul 2010 13:06:33 -0400 Subject: [PATCH] Fixing fatal error caused by associated models using a datasource that is not a subclass of dbo_source. Test added. Fixes #873 --- cake/libs/model/datasources/dbo_source.php | 2 +- .../libs/model/datasources/dbo_source.test.php | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/cake/libs/model/datasources/dbo_source.php b/cake/libs/model/datasources/dbo_source.php index b717ee00a..35be891be 100755 --- a/cake/libs/model/datasources/dbo_source.php +++ b/cake/libs/model/datasources/dbo_source.php @@ -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); diff --git a/cake/tests/cases/libs/model/datasources/dbo_source.test.php b/cake/tests/cases/libs/model/datasources/dbo_source.test.php index 8dda31f00..5ef6d396f 100644 --- a/cake/tests/cases/libs/model/datasources/dbo_source.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo_source.test.php @@ -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)); + } }