Count query with group in class extends \yii\db\Query
Author: sallfrisCreated Mar 17, 2023Updated May 30, 2026
Labelstype:feature
What steps will reproduce the problem?
- Create class QueryMyDb extends \yii\db\Query
- Modify function in QueryModified
public function createCommand($db = null)
{
if ($db === null) {
$db = Yii::$app->get('myDb');
}
return parent::createCommand($db);
}- Execute request
(new QueryMyDb())->from('table')
->groupBy('column')
->count();What is the expected result?
Query to myDb
What do you get instead?
Query to db
Additional info
Problem this
If use (new static()), the query will be correct
| Q | A |
|---|---|
| Yii version | 2.0.47 |
| PHP version | 7.2 |
| Operating system | unix |
Source: yiisoft/yii2