Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query::select removes fields if it passed twice #15676

Closed
rdeanar opened this issue Feb 19, 2018 · 5 comments
Closed

Query::select removes fields if it passed twice #15676

rdeanar opened this issue Feb 19, 2018 · 5 comments
Assignees
Labels
Milestone

Comments

@rdeanar
Copy link

rdeanar commented Feb 19, 2018

After updating from 2.0.13 to 2.0.14 i have noticed some strange behavior of Query::select().
If you reassign select fields, duplicates will be removed like in example below:

What steps will reproduce the problem?

$query = (new yii\db\Query())
            ->select('id')
            ->from('place')
        ;
$query->select(['id', 'brand_id']);
return $query->one();

What is the expected result?

[
'id' => 1,
'brand_id' => 1,
]

What do you get instead?

[
'brand_id' => 1,
]

Additional info

Notice: if define id inside select with alias in first or second definition (i.e ['id_alias' => 'id']), it will be ok and id will be selected.

It seems that such behavior occurs because of Query::getUniqueColumns(), added in 2.0.14.

Maybe related with: #15674

Q A
Yii version 2.0.14
PHP version 7.1.14
DB mysql 5.7
@samdark samdark added this to the 2.0.14.1 milestone Feb 19, 2018
@SilverFire SilverFire self-assigned this Feb 19, 2018
@SilverFire SilverFire added the type:bug Bug label Feb 19, 2018
@SilverFire
Copy link
Member

Fixed, thank you

@demenkov
Copy link

demenkov commented Feb 21, 2018

with fix isn't worked on select's like

->select([
'prefix' => 'LEFT(name, 7)',
'prefix_key' => 'LEFT(name, 7)',
])

because array_unique filtered out without compare array keys

@SilverFire
Copy link
Member

Could you open a separate issue, please?

@demenkov
Copy link

Please, #15728

@SilverFire
Copy link
Member

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants