mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
Related Objects not Hydrated at all despite fetch:EAGER #7307
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 @craigh on GitHub (Jan 31, 2024).
Bug Report
Summary
No matter how "EAGER" the query, I keep getting a proxy object.
Current behavior
I have a query like
The
recordobject (obviously) has relationsIf I run the query and dump the results
The BoardMember object in each Record object is a Proxy and that Proxy has NO VALUES. Additionally, the proxy doesn't fetch the values when they are called. The values are all simply
unset.I am using this via Symfony 6.4.3 and I have configured Symfony doctrine/doctrine-bundle 2.11.1 like so:
I also tried
in the query, but that made no change.
I also tried
instead of
getResultand the arrays are fully hydrated correctly but I would prefer the objects...This worked previously, with Symfony 5 ( I know you're not Symfony) but the
enable_lazy_ghost_objectsvalue changed for that fromfalsetotrueso may be related. Changing this back tofalsedoes seem to fix my problem (Object is still a proxy but has needed values in it). But then I have the depreciation warnings again. So I'd like to fix the other problem...Expected behavior
I expect the object to by fully hydrated since the
fetch:EAGERproperty is set. I would also expect the Proxy to fetch the value if I called it.@wmouwen commented on GitHub (Feb 26, 2024):
Loosely relates to #11185
@stof commented on GitHub (Mar 6, 2024):
If a proxy object already exists in the identity map of the ORM, you will still get it (even though it might be an initialized proxy at some point) because the identity map must only manage one object instance for each database id (by design), and it cannot replace it by a different one (as it does not have any way to replace the other references to that object in other entities already instantiated). That's why you might still get a proxy object
@craigh commented on GitHub (Mar 6, 2024):
@stof are you saying that if I have two
fetchactions for that entity, I might be creating a proxy in the first and then on the second fetch getting that same proxy instead of the fully hydrated object? (and thank you for answering, I still have not solved this)@stof commented on GitHub (Mar 7, 2024):
@craigh the second fetch will indeed get the same object instance (whether it gets hydrated or no during the second fetch depends on the case).
@linuxprocess commented on GitHub (Oct 15, 2024):
Hi @craigh
You can try to force doctrine to fetch all join entities in your createQueryBuilder with addSelect() like this :
@philepsybo commented on GitHub (Nov 19, 2025):
This hit me quite unexpectedly today I gotta admit. It would be nice to be able to trigger eager-fetching through the query builder without having to join everything manually. In some cases simply configuring it through the entity alone is not really flexible enough.
I often deal with such issues in workflow-event-listeners.