mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-03 22:32:40 +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:
@ -4,6 +4,7 @@ Yii Framework 2 Change Log
|
||||
2.0.41 under development
|
||||
------------------------
|
||||
|
||||
- Enh #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()` (OndrejVasicek, samdark, bizley)
|
||||
- Enh #18483: Add `yii\log\Logger::$dbEventNames` that allows specifying event names used to get statistical results (profiling) of DB queries (atiline)
|
||||
- Enh #18455: Add ability to use separate attributes for data model and filter model of `yii\grid\GridView` in `yii\grid\DataColumn` (PowerGamer1)
|
||||
- Enh #18447: Do not use `getLastInsertID` to get PK from insert query to lower collision probability for concurrent inserts (darkdef)
|
||||
|
||||
@ -53,6 +53,8 @@ interface ActiveQueryInterface extends QueryInterface
|
||||
* // return the index value corresponding to $model
|
||||
* }
|
||||
* ```
|
||||
* The column has to be a part of the `SELECT` fragment of a SQL statement.
|
||||
* If [[yii\db\Query::select()|select()]] is used with an array in its parameter, Yii handles adding that required SQL fragment for you.
|
||||
*
|
||||
* @return $this the query object itself
|
||||
*/
|
||||
|
||||
@ -245,7 +245,16 @@ class Query extends Component implements QueryInterface, ExpressionInterface
|
||||
if ($this->emulateExecution) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (is_string($this->indexBy) && $this->indexBy && is_array($this->select) && !in_array($this->indexBy, $this->select)) {
|
||||
if (strpos($this->indexBy, '.') === false && count($tables = $this->getTablesUsedInFrom()) > 0) {
|
||||
$this->select[] = key($tables) . '.' . $this->indexBy;
|
||||
} else {
|
||||
$this->select[] = $this->indexBy;
|
||||
}
|
||||
}
|
||||
$rows = $this->createCommand($db)->queryAll();
|
||||
|
||||
return $this->populate($rows);
|
||||
}
|
||||
|
||||
|
||||
@ -68,6 +68,8 @@ interface QueryInterface
|
||||
* // return the index value corresponding to $row
|
||||
* }
|
||||
* ```
|
||||
* The column has to be a part of the `SELECT` fragment of a SQL statement.
|
||||
* If [[yii\db\Query::select()|select()]] is used with an array in its parameter, Yii handles adding that required SQL fragment for you.
|
||||
*
|
||||
* @return $this the query object itself
|
||||
*/
|
||||
|
||||
@ -71,6 +71,8 @@ trait QueryTrait
|
||||
* // return the index value corresponding to $row
|
||||
* }
|
||||
* ```
|
||||
* The column has to be a part of the `SELECT` fragment of a SQL statement.
|
||||
* If [[yii\db\Query::select()|select()]] is used with an array in its parameter, Yii handles adding that required SQL fragment for you.
|
||||
*
|
||||
* @return $this the query object itself
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user