mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
[PR #11870] Make generated QueryComponents publicly available in ParserResult #13304
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?
Original Pull Request: https://github.com/doctrine/orm/pull/11870
State: closed
Merged: No
The Parser turns A DQL query in a ParserResult. This parser generates all the QueryComponents, which hold all the mappings calculated from the DQL query. But in the end these calculated components are never consultable. This is actually very useful information but you can't access it anywhere. So that really is a pity!
A scenario where access to this generated data becomes very useful is when you have a QueryBuilder with subQueries which are injected with DQL.
Let's say you have a dynamic query builder that goes through a lot of code and might add subqueries along the way.
In the end just before executing the query I want to check my QueryBuilder if it has at least one ...toMany relation before I add
I only want to add distinct or groupBy if it is really necessary because it is a performance hit. There is no need to add it if we don't have toMany relations in the final query.
Because we have DQL injected in our query we lose the original "$subqueryBuilder" join mapping information in the final $queryBuilder
So By adding the generated QueryComponents to the ParserResult all the oh-so-valuable mapping information with all the join types becomes available.
To solve this problem in my current project I made this solution with a ReflectionClass to access the private generated "queryComponents"
But it would be nice that we all could just do $parserResult->getQueryComponents(), and then we can check if there is at least one ...toMany relation with