Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
View
4 lib/Cake/Model/Model.php
@@ -2749,8 +2749,8 @@ protected function _findCount($state, $query, $results = array()) {
} elseif ($state === 'after') {
foreach (array(0, $this->alias) as $key) {
if (isset($results[0][$key]['count'])) {
- if (($count = count($results)) > 1) {
- return $count;
+ if ($query['group']) {
+ return count($results);
} else {
return intval($results[0][$key]['count']);
}
View
13 lib/Cake/Test/Case/Model/ModelReadTest.php
@@ -6860,6 +6860,17 @@ public function testFindCount() {
));
$result = $Article->find('count', array('group' => array('Article.user_id')));
$this->assertEquals($expected, $result);
+
+ $expected = count($Article->find('all', array(
+ 'fields' => array('Article.user_id'),
+ 'conditions' => array('Article.user_id' => 1),
+ 'group' => 'Article.user_id')
+ ));
+ $result = $Article->find('count', array(
+ 'conditions' => array('Article.user_id' => 1),
+ 'group' => array('Article.user_id'),
+ ));
+ $this->assertEquals($expected, $result);
}
/**
@@ -6886,7 +6897,7 @@ public function testFindCountDistinct() {
$this->skipIf($this->db instanceof Sqlite, 'SELECT COUNT(DISTINCT field) is not compatible with SQLite.');
$this->skipIf($this->db instanceof Sqlserver, 'This test is not compatible with SQL Server.');
- $this->loadFixtures('Project');
+ $this->loadFixtures('Project', 'Thread');
$TestModel = new Project();
$TestModel->create(array('name' => 'project')) && $TestModel->save();
$TestModel->create(array('name' => 'project')) && $TestModel->save();

0 comments on commit 33a879f

Please sign in to comment.
Something went wrong with that request. Please try again.