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:
Ondřej Vašíček
2021-02-23 16:44:39 +01:00
committed by GitHub
parent 4ed14bb738
commit d1037db68d
7 changed files with 37 additions and 0 deletions

View File

@ -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);
}
}