mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
[question] Association partial id retrieval/hydratation #5295
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 @soyuka on GitHub (Oct 18, 2016).
Hi,
I was wondering how (and if it is possible) to retrieve an identity of a foreign entity, without joining it. I mean, we already know the foreign entity identifier if it is in a relation table and it might return a
Proxyobject with identifiers only no?Note, I'm using
HINT_FORCE_PARTIAL_LOADbecause of #2094I tried those to retrieve an identity through partial selection:
SELECT PARTIAL alias.{id, field, association}becauseassociationis not infieldMappingit will be removed by theSqlWalker.SELECT PARTIAL alias.{id, field}, IDENTITY(alias.association)this works, but the field won't be hydrated. Is there a reason why hydratation doesn't work throughIDENTITY?I think the second example may work by tweaking the
resultSetMappingso that hydratation works, but I didn't try yet.Note, that this may work the same for associations, for example:
Here, the expected result would be an object:
Could this be implemented? Is this a bad idea (why?)?
@coudenysj commented on GitHub (Oct 18, 2016):
If you just fetch the \Entity\Foo object, the association field will contain an \Entity\Bar proxy object (not initialised). If you then call getField() on the association object, the data will be fetched (lazy loading), but if you call getId() on the association object, no lazy loading will occur, because the id is already know.
Does this answers your question?
@soyuka commented on GitHub (Oct 18, 2016):
Thanks I need to try this and will get back to you!
On Tue, 18 Oct 2016 at 19:59, Jachim Coudenys notifications@github.com
wrote:
@soyuka commented on GitHub (Oct 19, 2016):
@coudenysj So, getting those identifiers would work if the initial query was getting back association identifiers. When using
partial, because of #2094 you have to useHINT_FORCE_PARTIAL_LOADto avoid lazy joins. Because of this, every columns you select that is an association will be removed from the query string.For example:
This means that associations are
nulland you can not call thegetIdon them.Note that if you join the association, it'll work but will do an extra join if you don't need it.
IMO it has to do with this but I'm not sure if this can easily be fixed.
@soyuka commented on GitHub (Oct 19, 2016):
Narrowed it down to those both conditions.
Anyway, there must be something wrong during hydratation too because fields are still null.
@coudenysj commented on GitHub (Oct 19, 2016):
Why do you still use partial loading? Cant you just discard the 'select' method and load the complete object? The references will contain the proxy association objects then.
@soyuka commented on GitHub (Oct 19, 2016):
Because I don't want my other association (which is on an EAGER fetched association) to be lazy loaded.
Here is a full example of the data structure (without getters/setters):
What I'm trying to get is:
If I'm not using partial on
barit'll lazy loadbar.association, which is something I don't want.@soyuka commented on GitHub (Oct 19, 2016):
Ok my bad, I missunderstood partial loading. I think I managed to get want I wanted by only calling
getId! Thanks @coudenysj