Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix find('count') with 'group' when result has only one group. Closes #…

  • Loading branch information...
commit 33a879ff411928429a5b0188a68eecd9632f87e3 1 parent 1234f96
ADmad ADmad authored
4 lib/Cake/Model/Model.php
View
@@ -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']);
}
13 lib/Cake/Test/Case/Model/ModelReadTest.php
View
@@ -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();
Please sign in to comment.
Something went wrong with that request. Please try again.