mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
DDC-2841: Preload data for association #3547
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 @doctrinebot on GitHub (Dec 6, 2013).
Originally assigned to: @Ocramius on GitHub.
Jira issue originally created by user sparrowek:
Consider two classes User and Address with one-to-many association.
I would like to preload addresses for given user object so that it will be accessible via getter method like this:
Currently the only solution for step 2 I found working is to write a DQL like this:
SELECT u, a
FROM User
INNER JOIN u.addresses a
WHERE u = :user AND a.foo = 1
When the data is hydrated it is assigned to the user object and thus accessible with $user->getAddresses (which normally would return all the addresess not only those with foo set)
The only problem is that the query in step 2 unnecessarily fetches all user data that was already fetched in step 1
@mochja commented on GitHub (Oct 17, 2019):
Any update on this one? Can we achieve this without fetching the user data again?
@Fedik commented on GitHub (Oct 18, 2019):
Much depend from type of association,
for M2O could be:
SELECT a FROM Address WHERE a.user = :user
@Ocramius commented on GitHub (Oct 18, 2019):
I'd say that a fetch-joined DQL query is the correct approach, and that this feature is already implemented that way, as described in the OP.
Closing here as
won't fix.