N
N
nepster-web2017-12-12 22:09:03
Doctrine ORM
nepster-web, 2017-12-12 22:09:03

Doctrine, is there a solution for optimal sampling and association search?

While working with Doctrine, I ran into fetch issues where the query gets a bit more complex.
Let's imagine a classic situation:
there is an article, the article has tags (meni to mani), there are images, some labels, and so on.
Suppose we need a little optimization when we need to return everything at once (100 articles and all images and all tags for them). If we use lazy loading, it will turn out that, with the first request, we will get all the articles, and then we will make a request for images and tags for each, as a result of 202 requests.
This is not good, so we make a join where it is needed. Using an example of how AR works, say in Yii2, it optimizes this business as follows: it takes all the articles, all the images for these articles, all the categories for these articles and compares. Therefore it is possible to keep within 3 requests for example.
As I understand it, there is nothing similar in the doctrine. And when you need to add a certain condition for the association: find all articles that have a certain tag, and so on. and plus to make joins for optimization, it turns out that the doctrine can incorrectly give records.
In my case, with all the joins and filters, the doctrine did not return all the entries by the filter, but let's say only those where there are images. For example: I want all posts with the tag Vasya, it doesn't matter if there are images or not. The doctrine in some situations has its own opinion on this matter and I get all posts with the Vasya tag and only those with images. Of course, if you remove the join on the images, everything will be fine.
Based on this, I had to manually implement what AR does. Separately, take images, categories, and substitute reflection. The code turned out to be cumbersome and I would like to know if there are solutions that make life easier?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question