Skip to content


DDC-2841: Preload data for association #3595

doctrinebot opened this Issue · 0 comments

2 participants


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:

  1. $user = $userRepository->find($userId);
  2. load some of the addresses but not all
  3. $user->getAddresses() should return those loaded in step 2

Currently the only solution for step 2 I found working is to write a DQL like this:
INNER JOIN u.addresses a
WHERE u = :user AND = 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

@beberlei beberlei was assigned by doctrinebot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.