mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Querying DTOs with INDEX BY #6853
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 @flaushi on GitHub (Oct 6, 2021).
Bug Report
Summary
Results from a DTO-query with INDEX BY are not correctly indexed. I am getting standard arrays instead.
Current behavior
if I query
SELECT x.name FROM Entity x INDEX BY x.namethe result is array like['alice' => 'alice', 'bob' => 'bob', ...]however
will return `[0 => Dto('alice'), 1 => DTO('bob'), ...]
Expected behavior
I would expect to get
['alice' =>DTO( 'alice'), 'bob' => DTO('bob'), ...]In view that partial queries are deprecated and that DTOs should replace them, the index by feature might be important for all developers who used index-by together with partial objects until now and have to migrate. For partial objects, this worked fine.
@nCrazed commented on GitHub (Dec 22, 2021):
Running into the same problem in version
2.7.3@greg0ire commented on GitHub (Feb 1, 2022):
Duplicate of https://github.com/doctrine/orm/issues/4415
@greg0ire commented on GitHub (Feb 1, 2022):
We've been looking into this with @sir-kain , and it seems that
ResultSetMapping::addIndexBy()does nothing, because it does not know how to mapA.titleto an SQL column. Thisforeachhas nothing to loop on:536b65f02b/lib/Doctrine/ORM/Query/ResultSetMapping.php (L222)Not sure if we should have another lookup map, or if one of those should be modified, here maybe:
536b65f02b/lib/Doctrine/ORM/Query/SqlWalker.php (L1592-L1604)I tried and failed to do so by using
addFieldResult, that resulted in an error during hydration later on:536b65f02b/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php (L320-L321)$rowData['data']became not empty and thealiasMapwas missing the required key for the code to continue, which it probably shouldn't.@sir-kain has written the following test in case anyone wants to continue this:
@Arkemlar commented on GitHub (Dec 13, 2023):
Bump it (version 2.15.3)