From 0f7d6a90a17e7d00c99e3cfd62497d0dfb40a98e Mon Sep 17 00:00:00 2001 From: Andy Hobbs Date: Thu, 26 Sep 2013 11:56:14 +0100 Subject: [PATCH] Ticket 4108 - Added schemaName to DboSource::fields() method cache key to fix bug with changing schema name --- lib/Cake/Model/Datasource/DboSource.php | 1 + .../Case/Model/Datasource/DboSourceTest.php | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/lib/Cake/Model/Datasource/DboSource.php b/lib/Cake/Model/Datasource/DboSource.php index 159d5a811..57cb276fc 100644 --- a/lib/Cake/Model/Datasource/DboSource.php +++ b/lib/Cake/Model/Datasource/DboSource.php @@ -2281,6 +2281,7 @@ class DboSource extends DataSource { $fields, $quote, ConnectionManager::getSourceName($this), + $model->schemaName, $model->table ); $cacheKey = md5(serialize($cacheKey)); diff --git a/lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php b/lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php index 9c37e91ef..bcfd5a060 100644 --- a/lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php +++ b/lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php @@ -945,6 +945,28 @@ class DboSourceTest extends CakeTestCase { $this->assertEquals(2, count(DboTestSource::$methodCache['fields'])); } +/** + * test that fields() method cache detects schema name changes + * + * @return void + */ + public function testFieldsCacheKeyWithSchemanameChange() { + Cache::delete('method_cache', '_cake_core_'); + DboSource::$methodCache = array(); + $Article = ClassRegistry::init('Article'); + + $ds = $Article->getDataSource(); + $ds->cacheMethods = true; + $first = $ds->fields($Article); + + $Article->schemaName = 'secondSchema'; + $ds = $Article->getDataSource(); + $ds->cacheMethods = true; + $second = $ds->fields($Article); + + $this->assertEquals(2, count(DboSource::$methodCache['fields'])); + } + /** * Test that group works without a model *