mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
AbstractQuery::toIterable is not a full replacement for AbstractQuery::iterate #6881
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 @stof on GitHub (Dec 3, 2021).
Bug Report
Summary
The new
AbstractQuery::toIterablemethod does not support hydrating mixed results, while the deprecatedAbstractQuery::iteratewas supporting it. This means that it is not always possible to migrate from the deprecated API to its replacement API (and so that some cases would not be possible in ORM 3.0).It would be great to support it.
@derrabus commented on GitHub (Dec 3, 2021):
Can you provide an example of a piece of code that cannot be migrated to the new API?
@stof commented on GitHub (Dec 3, 2021):
@derrabus any query selecting both an entity result and additional scalar results in its ResultSetMapping (be it in DQL or through
createNativeQuery()@stof commented on GitHub (Dec 3, 2021):
This is the code that is explicitly treating it as unsupported:
7b24275346/lib/Doctrine/ORM/AbstractQuery.php (L1091-L1093)However, removing this condition is not enough, as
\Doctrine\ORM\Internal\Hydration\AbstractHydrator::toIterabledoes not support it AFAICT.@beberlei commented on GitHub (Dec 18, 2021):
Yes this is a known problem, we need to adress this in the generator, but I haven't found a way yet that does not lead to bugs in edge cases.
@stof commented on GitHub (Dec 20, 2021):
For reference, here is the code I'm using since years in my project (but I don't guarantee that it covers all edge cases):
@kbond commented on GitHub (Feb 24, 2022):
Related to https://github.com/doctrine/orm/issues/8520. Possible solution: https://github.com/doctrine/orm/pull/8555?
As a workaround, I use the paginator to chunk the results and iterate from each chunk.
@stof commented on GitHub (Dec 15, 2025):
This has been fixed in https://github.com/doctrine/orm/pull/12187