diff --git a/lib/Cake/Model/Model.php b/lib/Cake/Model/Model.php index 11de1e8c0..8797172e4 100644 --- a/lib/Cake/Model/Model.php +++ b/lib/Cake/Model/Model.php @@ -843,6 +843,7 @@ class Model extends Object implements CakeEventListener { } } + if (!$className) { return false; } @@ -1128,7 +1129,7 @@ class Model extends Object implements CakeEventListener { if (method_exists($db, 'listSources')) { $restore = $db->cacheSources; - $db->cacheSources = $this->cacheSources; + $db->cacheSources = ($restore && $this->cacheSources); $sources = $db->listSources(); $db->cacheSources = $restore; diff --git a/lib/Cake/Test/Case/Model/ModelIntegrationTest.php b/lib/Cake/Test/Case/Model/ModelIntegrationTest.php index b73cd8e6b..2eb194289 100644 --- a/lib/Cake/Test/Case/Model/ModelIntegrationTest.php +++ b/lib/Cake/Test/Case/Model/ModelIntegrationTest.php @@ -155,17 +155,17 @@ class ModelIntegrationTest extends BaseModelTest { } /** - * Tests that $cacheSources can only be disabled in the db using model settings, not enabled + * Tests that $cacheSources is restored despite the settings on the model. * * @return void */ - public function testCacheSourcesDisabling() { + public function testCacheSourcesRestored() { $this->loadFixtures('JoinA', 'JoinB', 'JoinAB', 'JoinC', 'JoinAC'); $this->db->cacheSources = true; $TestModel = new JoinA(); $TestModel->cacheSources = false; $TestModel->setSource('join_as'); - $this->assertFalse($this->db->cacheSources); + $this->assertTrue($this->db->cacheSources); $this->db->cacheSources = false; $TestModel = new JoinA();