Fixing my previous attempt in ef4826e to make Model::_findCount() behave nicely with 'group' option. Refs #1677, #573

This commit is contained in:
ADmad 2011-09-28 02:58:48 +05:30
parent 7e44836837
commit 33030a4502
2 changed files with 6 additions and 4 deletions

View file

@ -2433,7 +2433,7 @@ class Model extends Object {
* - 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 @@ class Model extends Object {
} 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 file

@ -6591,8 +6591,10 @@ class ModelReadTest extends BaseModelTest {
$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);
}
/**