-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Honor INDEX BY construct in Query::toIterable #9098
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
Conversation
a3de308
to
583de03
Compare
@@ -196,7 +197,7 @@ public function toIterable($stmt, ResultSetMapping $resultSetMapping, array $hin | |||
$this->cleanupAfterRowIteration(); | |||
|
|||
if (count($result) === 1) { | |||
yield end($result); | |||
yield array_keys($result)[count($result) - 1] => end($result); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain why this works? Is the key for INDEX BY
always the last one for some reason?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was a polyfill for array_last_key
. We have to return the last key, because current code is returning last position of the $result
array.
But after reading the code again, if count($result) === 1
it could be rewritten as a simple yield from $result
.
459db29
to
6d96f69
Compare
@greg0ire After reviewing the code again, I think the problem exposed in #8927 is finally a bug. I've found that the tests use
After fixing it, I've found another bug: when selecting multiple entities, the results from |
Please kindly squash your commits together. If you don't, we'll try to remember to do it for you but it's best if you save us this trouble. How to do that?
|
6d96f69
to
483e09c
Compare
@greg0ire Squashed!! |
Thanks @ajgarlag ! |
Fix the problem explained in #8927 as a bug fix.
Alternative implementation as a feature in #9099.