Manually Hydrate Entities of Collection over Relationship #9366
Unanswered
Hanmac
asked this question in
Support Questions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi i have the following Stucture:
a User Object
a Product Object
a Image Object
a UserProductImages Object (This was a JoinTable from a M-N which is now a M-1-N)
the main part where i need this is to display a Table in Front-end that shows:
i once had a M-N Relationship between Product and Images but that was replaced by a M-1-N Relationship.
Now to my real problem:
i want to manually hydrate the entities' relationships to reduce the amount of Database Queries.
I try to do that without fetch=EAGER so it doesn't load unnecessary stuff while in the Sonata Back-end.
I load the User Object from the UserProvider, then i can already load the Images, Products and the Product Images because they are connected to the User.
Now i have a Collection of Products and i want to load the 1-M ProductImages relationship in ONE Database Query if possible.
Currently it does try to ask the ProdutImages for each Product in the List. (which would be N Queries instead of one)
I tried this Query, which should load all Products and their ProductImages connected to a User, but i can't get it to hydrate the product entities i would load from the User object anyway.
Fixed Query because i didn't understand the join before:
this is somehow better so that i need way less queries and time, but it still annoys me that it needs to load the products twice, and loading just the UserProductImages with all the three keys (User, Product, Image) isn't enough to populate the the Relationship between Product and UserProductImages
Beta Was this translation helpful? Give feedback.
All reactions