mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
SELECT entity with multiple GROUP BY returns partial result #5698
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @BenMorel on GitHub (Sep 12, 2017).
I have 3 entities:
I'm trying to select the total commission amounts, for each network, grouped by currency.
This translates into
GROUP BY network, merchant.currencyCode.If I select
Network.idonly, it works fine:Now if I select the
Networkentity:It still works fine when using
HYDRATE_ARRAY:But when using
HYDRATE_OBJECT, it only returns the last result for each Network:I created a reproducible example in this repository:
https://github.com/BenMorel/doctrine-groupBy-bug
I could not find any documentation for this behaviour, which I believe is a bug, as it behaves differently based on the hydration mode, in addition to being counter-intuitive.
@beberlei commented on GitHub (Sep 16, 2017):
This is the expected behaviour, the object hydration returns exactly one object of each type, in this case overwriting the mixed result group by values.
I just checked and you are right about this not being documented, so I have added it to the docs for the next person:
0c4f9a8866@BenMorel commented on GitHub (Sep 16, 2017):
Interesting, thanks. Is there any technical reason why it behaves this way? Would it be possible to create another object hydrator that would behave as I expected?
At the moment I have to retrieve Network ids instead, and do a separate
SELECT ... WHERE id in(...)query to load the Networks separately.