From 1940d8877caf2ce08347a7ecfadd609740faa0f1 Mon Sep 17 00:00:00 2001 From: nate Date: Wed, 27 Aug 2008 04:55:15 +0000 Subject: [PATCH] Fixing Model/db $cacheSources conflicts, model can now disable only. Fixes #5177 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7518 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/model/model.php | 4 ++-- cake/tests/cases/libs/model/model.test.php | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) 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