-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Add note about Query::HINT_INCLUDE_META_COLUMNS
for custom hydrators
#11461
base: 2.19.x
Are you sure you want to change the base?
Conversation
Actually using this doesn't work because Query and SqlWalker are executed before the custom hydrator is called so the hint I set in my 1^ "sqlWalker"
2^ []
^ array:1 [
0 => "c0_.id AS id_0, c0_.name AS name_1"
]
1^ "customHydrator.prepare"
2^ array:2 [
"deferEagerLoad" => true
"doctrine.includeMetaColumns" => true
] |
After a lot of thinking, I found a (not good looking, but working) method to make this works, I still think it should be documentated somewhere that this hint exists and what it does. For my use-case I made a static method: public static function getResult(Query $query): mixed
{
$query->setHint(Query::HINT_INCLUDE_META_COLUMNS, true);
return $query->getResult('automapper');
} And then, when you want the result of a query: $qb = $userRepository->createQueryBuilder('u');
$resultAutoMapper = AutoMapperHydrator::getResult($qb->getQuery()); It's not that bad and doesn't require too much for the end-user but I still think it would be better if we could set this elsewhere. |
@@ -1370,6 +1370,9 @@ userland: | |||
- ``Query::HINT_CUSTOM_TREE_WALKERS`` - An array of additional | |||
``Doctrine\ORM\Query\TreeWalker`` instances that are attached to | |||
the DQL query parsing process. | |||
- ``Query::HINT_INCLUDE_META_COLUMNS`` - A boolean that causes | |||
meta columns like foreign keys and discriminator columns to be | |||
selected and returned as part of the query 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.
If it's not really usable, then we should maybe not document it at all, or at least let the users who are curious about it know that it's used internally. Like you, they might be able to leverage it through a few hacks, but it's clearly not designed to be used outside Doctrine itself. That could be challenged, and the design improved, I suppose.
Hey !
I was trying to create a custom hydrator that handle everything the same as
ObjectHydrator
and I was not understanding WHY I don't have meta columns when using my hydrator whileObjectHydrator
had them.After some search I found: https://github.com/doctrine/orm/blob/3.1.x/src/Query/SqlWalker.php#L647-L648 that forces meta columns when using
ObjectHydrator
but for any other hydrator you have to pass the hint.So I added a note about that hint in the custom hydrator documentation so people knows about this 😉