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
|
@ -2433,7 +2433,7 @@ class Model extends Object {
|
||||||
* - If three fields are specified, they are used (in order) for key, value and group.
|
* - 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.
|
* - 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.
|
* have issues with database views.
|
||||||
* @param string $type Type of find operation (all / first / count / neighbors / list / threaded)
|
* @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)
|
* @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') {
|
} elseif ($state === 'after') {
|
||||||
foreach (array(0, $this->alias) as $key) {
|
foreach (array(0, $this->alias) as $key) {
|
||||||
if (isset($results[0][$key]['count'])) {
|
if (isset($results[0][$key]['count'])) {
|
||||||
if (count($results) > 1) {
|
if (($count = count($results)) > 1) {
|
||||||
return intval(array_sum(Set::extract('/' . $key . '/count', $results)));
|
return $count;
|
||||||
} else {
|
} else {
|
||||||
return intval($results[0][$key]['count']);
|
return intval($results[0][$key]['count']);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6591,8 +6591,10 @@ class ModelReadTest extends BaseModelTest {
|
||||||
$this->assertNoPattern('/ORDER\s+BY/', $log['log'][0]['query']);
|
$this->assertNoPattern('/ORDER\s+BY/', $log['log'][0]['query']);
|
||||||
|
|
||||||
$Article = new Article();
|
$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'));
|
$result = $Article->find('count', array('group' => 'Article.user_id'));
|
||||||
$this->assertEqual($result, 3);
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue