Skip to content

Commit

Permalink
Only check for existing method expresion() when it actually will be c…
Browse files Browse the repository at this point in the history
…alled.

Datasources that use calculate() should not be forced to implement expression() as well
  • Loading branch information
ceeram committed Apr 5, 2012
1 parent 8c631fa commit 30268f6
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/Cake/Model/Model.php
Expand Up @@ -2749,12 +2749,12 @@ protected function _findCount($state, $query, $results = array()) {
if ($state === 'before') {
$db = $this->getDataSource();
$query['order'] = false;
if (!method_exists($db, 'calculate') || !method_exists($db, 'expression')) {
if (!method_exists($db, 'calculate')) {
return $query;
}
if (empty($query['fields'])) {
$query['fields'] = $db->calculate($this, 'count');
} elseif (is_string($query['fields']) && !preg_match('/count/i', $query['fields'])) {
} elseif (method_exists($db, 'expression') && is_string($query['fields']) && !preg_match('/count/i', $query['fields'])) {
$query['fields'] = $db->calculate($this, 'count', array(
$db->expression($query['fields']), 'count'
));
Expand Down

0 comments on commit 30268f6

Please sign in to comment.