Only check for existing method expresion() when it actually will be called.

Datasources that use calculate() should not be forced to implement expression() as well
This commit is contained in:
Ceeram 2012-04-05 23:15:18 +02:00
parent 8c631fa022
commit 30268f6a08

View file

@ -2749,12 +2749,12 @@ class Model extends Object implements CakeEventListener {
if ($state === 'before') { if ($state === 'before') {
$db = $this->getDataSource(); $db = $this->getDataSource();
$query['order'] = false; $query['order'] = false;
if (!method_exists($db, 'calculate') || !method_exists($db, 'expression')) { if (!method_exists($db, 'calculate')) {
return $query; return $query;
} }
if (empty($query['fields'])) { if (empty($query['fields'])) {
$query['fields'] = $db->calculate($this, 'count'); $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( $query['fields'] = $db->calculate($this, 'count', array(
$db->expression($query['fields']), 'count' $db->expression($query['fields']), 'count'
)); ));