Answer the question
In order to leave comments, you need to log in
Doctrine 2 relationships - how to solve the problem?
Faced such a problem, there is an entity (Products) with a oneToMany (Images) connection.
A request to select products is made through native sql, and the result is mapped into entity objects - Products using the result set mapper.
If the array of products is looped through and the Products->getImages() method is called in the loop, doctrine makes an image fetch request for each iteration. Those. if 100 products were selected, doctrine made 100 more requests to retrieve the image.
Maybe someone knows the options to get rid of these extra 100 requests? After all, according to the judge, you can get by with one, but how to do it in doctrine.
Answer the question
In order to leave comments, you need to log in
As an option, you can add native sql so that it also pulls out pictures, and hydrates products along with pictures.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question