mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
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:
parent
103346155f
commit
65efd675c1
2 changed files with 17 additions and 1 deletions
|
@ -841,7 +841,7 @@ class DboSource extends DataSource {
|
||||||
$db =& $this;
|
$db =& $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($db)) {
|
if (isset($db) && method_exists($db, 'queryAssociation')) {
|
||||||
$stack = array($assoc);
|
$stack = array($assoc);
|
||||||
$db->queryAssociation($model, $linkModel, $type, $assoc, $assocData, $array, true, $resultSet, $model->recursive - 1, $stack);
|
$db->queryAssociation($model, $linkModel, $type, $assoc, $assocData, $array, true, $resultSet, $model->recursive - 1, $stack);
|
||||||
unset($db);
|
unset($db);
|
||||||
|
|
|
@ -1339,6 +1339,7 @@ class DboSourceTest extends CakeTestCase {
|
||||||
function endTest() {
|
function endTest() {
|
||||||
unset($this->Model);
|
unset($this->Model);
|
||||||
Configure::write('debug', $this->debug);
|
Configure::write('debug', $this->debug);
|
||||||
|
ClassRegistry::flush();
|
||||||
unset($this->debug);
|
unset($this->debug);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4441,4 +4442,19 @@ class DboSourceTest extends CakeTestCase {
|
||||||
$result = $this->testDb->fullTableName($Article, false);
|
$result = $this->testDb->fullTableName($Article, false);
|
||||||
$this->assertEqual($result, 'tbl_articles');
|
$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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue