mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 11:06:15 +00:00
Fix find('count') with 'group' when result has only one group. Closes #1677
This commit is contained in:
parent
1234f96a6c
commit
33a879ff41
2 changed files with 14 additions and 3 deletions
|
@ -2749,8 +2749,8 @@ class Model extends Object implements CakeEventListener {
|
||||||
} 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 = count($results)) > 1) {
|
if ($query['group']) {
|
||||||
return $count;
|
return count($results);
|
||||||
} else {
|
} else {
|
||||||
return intval($results[0][$key]['count']);
|
return intval($results[0][$key]['count']);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6860,6 +6860,17 @@ class ModelReadTest extends BaseModelTest {
|
||||||
));
|
));
|
||||||
$result = $Article->find('count', array('group' => array('Article.user_id')));
|
$result = $Article->find('count', array('group' => array('Article.user_id')));
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
|
|
||||||
|
$expected = count($Article->find('all', array(
|
||||||
|
'fields' => array('Article.user_id'),
|
||||||
|
'conditions' => array('Article.user_id' => 1),
|
||||||
|
'group' => 'Article.user_id')
|
||||||
|
));
|
||||||
|
$result = $Article->find('count', array(
|
||||||
|
'conditions' => array('Article.user_id' => 1),
|
||||||
|
'group' => array('Article.user_id'),
|
||||||
|
));
|
||||||
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -6886,7 +6897,7 @@ class ModelReadTest extends BaseModelTest {
|
||||||
$this->skipIf($this->db instanceof Sqlite, 'SELECT COUNT(DISTINCT field) is not compatible with SQLite.');
|
$this->skipIf($this->db instanceof Sqlite, 'SELECT COUNT(DISTINCT field) is not compatible with SQLite.');
|
||||||
$this->skipIf($this->db instanceof Sqlserver, 'This test is not compatible with SQL Server.');
|
$this->skipIf($this->db instanceof Sqlserver, 'This test is not compatible with SQL Server.');
|
||||||
|
|
||||||
$this->loadFixtures('Project');
|
$this->loadFixtures('Project', 'Thread');
|
||||||
$TestModel = new Project();
|
$TestModel = new Project();
|
||||||
$TestModel->create(array('name' => 'project')) && $TestModel->save();
|
$TestModel->create(array('name' => 'project')) && $TestModel->save();
|
||||||
$TestModel->create(array('name' => 'project')) && $TestModel->save();
|
$TestModel->create(array('name' => 'project')) && $TestModel->save();
|
||||||
|
|
Loading…
Add table
Reference in a new issue