diff --git a/cake/libs/model/model.php b/cake/libs/model/model.php index 35cf5e793..5833c5818 100644 --- a/cake/libs/model/model.php +++ b/cake/libs/model/model.php @@ -694,7 +694,7 @@ class Model extends Overloadable { function setSource($tableName) { $this->setDataSource($this->useDbConfig); $db =& ConnectionManager::getDataSource($this->useDbConfig); - $db->cacheSources = $this->cacheSources; + $db->cacheSources = ($this->cacheSources && $db->cacheSources); if ($db->isInterfaceSupported('listSources')) { $sources = $db->listSources(); @@ -823,7 +823,7 @@ class Model extends Overloadable { function schema($field = false) { if (!is_array($this->_schema) || $field === true) { $db =& ConnectionManager::getDataSource($this->useDbConfig); - $db->cacheSources = $this->cacheSources; + $db->cacheSources = ($this->cacheSources && $db->cacheSources); if ($db->isInterfaceSupported('describe') && $this->useTable !== false) { $this->_schema = $db->describe($this, $field); } elseif ($this->useTable === false) { diff --git a/cake/tests/cases/libs/model/model.test.php b/cake/tests/cases/libs/model/model.test.php index 1eb12900d..ff98bfc85 100644 --- a/cake/tests/cases/libs/model/model.test.php +++ b/cake/tests/cases/libs/model/model.test.php @@ -5620,6 +5620,25 @@ class ModelTest extends CakeTestCase { $result = $TestModel->JoinAsJoinB->findById(1); $this->assertEqual($result['JoinAsJoinB']['other'], $updatedValue); } +/** + * Tests that $cacheSources can only be disabled in the db using model settings, not enabled + * + * @access public + * @return void + */ + function testCacheSourcesDisabling() { + $this->db->cacheSources = true; + $TestModel = new JoinA(); + $TestModel->cacheSources = false; + $TestModel->setSource('join_as'); + $this->assertFalse($this->db->cacheSources); + + $this->db->cacheSources = false; + $TestModel = new JoinA(); + $TestModel->cacheSources = true; + $TestModel->setSource('join_as'); + $this->assertFalse($this->db->cacheSources); + } /** * endTest method * @@ -5630,4 +5649,5 @@ class ModelTest extends CakeTestCase { ClassRegistry::flush(); } } + ?> \ No newline at end of file