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

@ -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);
}
/**