mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Fixing my previous attempt in ef4826e
to make Model::_findCount() behave nicely with 'group' option. Refs #1677, #573
This commit is contained in:
parent
7e44836837
commit
33030a4502
2 changed files with 6 additions and 4 deletions
|
@ -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']);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue