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

indexBy(callable) not calling when used column() #12649

Closed
ziaratban opened this issue Oct 2, 2016 · 1 comment · Fixed by #12653
Closed

indexBy(callable) not calling when used column() #12649

ziaratban opened this issue Oct 2, 2016 · 1 comment · Fixed by #12653
Assignees
Labels
Milestone

Comments

@ziaratban
Copy link

What steps will reproduce the problem?

why indexBy() with a anonymous function not working ? but with a column name worked.
my code

print_r(
    Role::find()
        ->select(['name','id'])
        ->indexBy(function($row){
            #exit('fire'); #not run
            return $row['id']*3;
        })
    ->column()
);

What is the expected result?


(
    [12] => a
    [46] => b
    [313] => c
)

What do you get instead?


(
    [0] => a
    [1] => b
    [2] => c
)

Additional info

Q A
Yii version 2.0.9
PHP version 5.6.3
Operating system ?
@SilverFire SilverFire added the type:bug Bug label Oct 3, 2016
@SilverFire SilverFire added this to the 2.0.x milestone Oct 3, 2016
SilverFire added a commit to SilverFire/yii2 that referenced this issue Oct 3, 2016
@alex-code
Copy link
Contributor

alex-code commented Oct 3, 2016

Does it work if you use ->all();?
column() will just return the first column of data so it has nothing to index with.

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

Successfully merging a pull request may close this issue.

3 participants