mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-13 22:06:51 +08:00
Fix #18499: When using yii\db\Query::all()
and yii\db\Query::$indexBy
, the yii\db\Query::$indexBy
is auto inserted into yii\db\Query::$select
- the same as in yii\db\Query::column()
Co-authored-by: Bizley <pawel@positive.codes> Co-authored-by: Alexander Makarov <sam@rmcreative.ru>
This commit is contained in:
@ -716,6 +716,8 @@ $query = (new \yii\db\Query())
|
||||
->all();
|
||||
```
|
||||
|
||||
The column name passed into [[yii\db\Query::indexBy()|indexBy()]] method has to be a part of the `SELECT` fragment of a SQL statement. If [[yii\db\Query::select()|select()]] is not used, all columns are selected and therefore the condition is met. If [[yii\db\Query::select()|select()]] is used with an array in its parameter, Yii handles adding that required SQL fragment for you. This applies when using [[yii\db\Query::indexBy()|indexBy()]] with [[yii\db\Query::all()|all()]] or [[yii\db\Query::column()|column()]]. In other cases, like the following example with an anonymous function, is up to users themselves to take care of it.
|
||||
|
||||
To index by expression values, pass an anonymous function to the [[yii\db\Query::indexBy()|indexBy()]] method:
|
||||
|
||||
```php
|
||||
|
Reference in New Issue
Block a user