Skip to content

Commit

Permalink
Check method existence before calling.
Browse files Browse the repository at this point in the history
Datasource does not implemente calculate() or
expression().  Only call them if they exist.

Fixes #2535
  • Loading branch information
markstory committed Feb 5, 2012
1 parent f3b990b commit 4bb4040
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/Cake/Model/Model.php
Expand Up @@ -2589,14 +2589,17 @@ protected function _findFirst($state, $query, $results = array()) {
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')) {
return $query;
}
if (empty($query['fields'])) {
$query['fields'] = $db->calculate($this, 'count');
} elseif (is_string($query['fields']) && !preg_match('/count/i', $query['fields'])) {
$query['fields'] = $db->calculate($this, 'count', array(
$db->expression($query['fields']), 'count'
));
}
$query['order'] = false;
return $query;
} elseif ($state === 'after') {
foreach (array(0, $this->alias) as $key) {
Expand Down

0 comments on commit 4bb4040

Please sign in to comment.