Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixing my previous attempt in ef4826e to make Model::_findCount() beh…

…ave nicely with 'group' option. Refs #1677, #573
  • Loading branch information...
commit 33030a4502558a659d9af03d7264a190c8447ca9 1 parent 7e44836
@ADmad ADmad authored
View
6 lib/Cake/Model/Model.php
@@ -2433,7 +2433,7 @@ public function hasAny($conditions = null) {
* - If three fields are specified, they are used (in order) for key, value and group.
* - Otherwise, first and second fields are used for key and value.
*
- * Note: find(list) + database views have issues with MySQL 5.0. Try upgrading to MySQL 5.1 if you
+ * Note: find(list) + database views have issues with MySQL 5.0. Try upgrading to MySQL 5.1 if you
* have issues with database views.
* @param string $type Type of find operation (all / first / count / neighbors / list / threaded)
* @param array $query Option fields (conditions / fields / joins / limit / offset / order / page / group / callbacks)
@@ -2570,8 +2570,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($results) > 1) {
- return intval(array_sum(Set::extract('/' . $key . '/count', $results)));
+ if (($count = count($results)) > 1) {
+ return $count;
} else {
return intval($results[0][$key]['count']);
}
View
4 lib/Cake/Test/Case/Model/ModelReadTest.php
@@ -6591,8 +6591,10 @@ public function testFindCount() {
$this->assertNoPattern('/ORDER\s+BY/', $log['log'][0]['query']);
$Article = new Article();
+ $Article->recursive = -1;
+ $expected = count($Article->find('all', array('group' => 'Article.user_id')));
$result = $Article->find('count', array('group' => 'Article.user_id'));
- $this->assertEqual($result, 3);
+ $this->assertEquals($expected, $result);
}
/**
Please sign in to comment.
Something went wrong with that request. Please try again.