Permalink
Browse files

Making DboSource::fields() use cacheMethod() so it respects $cacheMet…

…hods.

Test added.
Fixes #1211
  • Loading branch information...
1 parent 077d1c5 commit 498417203b707779f438a7f9cf29f60449a09b3a @markstory markstory committed Oct 21, 2010
@@ -1958,8 +1958,8 @@ function fields(&$model, $alias = null, $fields = array(), $quote = true) {
$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 @@ function fields(&$model, $alias = null, $fields = array(), $quote = true) {
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));
}
/**
@@ -4577,4 +4577,18 @@ function testReadOnlyCallingQueryAssociationWhenDefined() {
$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');
+ }
}

0 comments on commit 4984172

Please sign in to comment.