From 4bb404085113b92221da84c37dac3cd7d6f7ec69 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 5 Feb 2012 12:54:20 -0500 Subject: [PATCH] Check method existence before calling. Datasource does not implemente calculate() or expression(). Only call them if they exist. Fixes #2535 --- lib/Cake/Model/Model.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Model/Model.php b/lib/Cake/Model/Model.php index 2d7486e4f..5b617d9b0 100644 --- a/lib/Cake/Model/Model.php +++ b/lib/Cake/Model/Model.php @@ -2589,6 +2589,10 @@ class Model extends Object { 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'])) { @@ -2596,7 +2600,6 @@ class Model extends Object { $db->expression($query['fields']), 'count' )); } - $query['order'] = false; return $query; } elseif ($state === 'after') { foreach (array(0, $this->alias) as $key) {