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

It should be possible to set a table alias on indexBy #17687

Closed
brandonkelly opened this issue Nov 25, 2019 · 1 comment
Closed

It should be possible to set a table alias on indexBy #17687

brandonkelly opened this issue Nov 25, 2019 · 1 comment
Labels
Milestone

Comments

@brandonkelly
Copy link
Contributor

yii\db\Query::$indexBy should support being set to an aliased column name, for example:

$query->indexBy('users.username');

Oddly, there already is half-baked support for this in column(), in that the FROM table alias is only prepended to the DB query if indexBy doesn’t already contain a .:

if (strpos($this->indexBy, '.') === false && count($tables = $this->getTablesUsedInFrom()) > 0) {

To complete the feature, the table alias just needs to be stripped out on this line, if set:

$results[$row[$this->indexBy]] = $value;

brandonkelly added a commit to brandonkelly/yii2 that referenced this issue Nov 25, 2019
@samdark samdark added the type:bug Bug label Nov 26, 2019
@samdark samdark added this to the 2.0.31 milestone Nov 26, 2019
@brandonkelly
Copy link
Contributor Author

Thanks @samdark!

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

2 participants