From 498417203b707779f438a7f9cf29f60449a09b3a Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 20 Oct 2010 22:28:31 -0400 Subject: [PATCH] Making DboSource::fields() use cacheMethod() so it respects $cacheMethods. Test added. Fixes #1211 --- cake/libs/model/datasources/dbo_source.php | 6 +++--- .../libs/model/datasources/dbo_source.test.php | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/cake/libs/model/datasources/dbo_source.php b/cake/libs/model/datasources/dbo_source.php index 60e592e14..3f82a09d9 100755 --- a/cake/libs/model/datasources/dbo_source.php +++ b/cake/libs/model/datasources/dbo_source.php @@ -1958,8 +1958,8 @@ class DboSource extends DataSource { $quote ); $cacheKey = crc32(serialize($cacheKey)); - if (isset($this->methodCache[__FUNCTION__][$cacheKey])) { - return $this->methodCache[__FUNCTION__][$cacheKey]; + if ($return = $this->cacheMethod(__FUNCTION__, $cacheKey)) { + return $return; } $allFields = empty($fields); if ($allFields) { @@ -2049,7 +2049,7 @@ class DboSource extends DataSource { if (!empty($virtual)) { $fields = array_merge($fields, $this->_constructVirtualFields($model, $alias, $virtual)); } - return $this->methodCache[__FUNCTION__][$cacheKey] = array_unique($fields); + return $this->cacheMethod(__FUNCTION__, $cacheKey, array_unique($fields)); } /** diff --git a/cake/tests/cases/libs/model/datasources/dbo_source.test.php b/cake/tests/cases/libs/model/datasources/dbo_source.test.php index afca0d6be..bcb11045d 100644 --- a/cake/tests/cases/libs/model/datasources/dbo_source.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo_source.test.php @@ -4577,4 +4577,18 @@ class DboSourceTest extends CakeTestCase { $result = $Article->find('all'); $this->assertTrue(is_array($result)); } + +/** + * test that fields() is using methodCache() + * + * @return void + */ + function testFieldsUsingMethodCache() { + $this->testDb->cacheMethods = false; + $this->assertTrue(empty($this->testDb->methodCache['fields']), 'Cache not empty'); + + $Article =& ClassRegistry::init('Article'); + $this->testDb->fields($Article, null, array('title', 'body', 'published')); + $this->assertTrue(empty($this->testDb->methodCache['fields']), 'Cache not empty'); + } }