mirror of
https://github.com/yiisoft/yii2.git
synced 2025-10-31 02:28:35 +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:
@ -795,4 +795,23 @@ abstract class QueryTest extends DatabaseTestCase
|
||||
$newQuery->withQueries
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see https://github.com/yiisoft/yii2/issues/18499
|
||||
*/
|
||||
public function testAllWithAutomaticallyAddedIndexedByColumn()
|
||||
{
|
||||
$db = $this->getConnection();
|
||||
|
||||
$result = (new Query())->from('customer')
|
||||
->select('name')
|
||||
->orderBy(['id' => SORT_DESC])
|
||||
->indexBy('id')
|
||||
->all($db);
|
||||
$this->assertEquals([
|
||||
3 => ['name' => 'user3', 'id' => 3],
|
||||
2 => ['name' => 'user2', 'id' => 2],
|
||||
1 => ['name' => 'user1', 'id' => 1]
|
||||
], $result);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user