Answer the question
In order to leave comments, you need to log in
Is there a convenient solution for complex queries?
While working with Doctrine2, I noticed that it is very convenient to save entity data with its help, but you need to tinker with the selections a lot. It is clear that this is not a problem of the ORM itself, but rather a matter of approaches, and yet I would like to find a convenient solution for the formation of universal and complex queries.
So, the example will be, as always, the simplest: there are posts, tags for them, pictures and an author.
The task is also simple: get a list of categories.
And besides this, there is also a list of specific optimization and filtering cases:
- List of posts
- List of posts with pictures
- List of posts with tags
- List of posts with pictures and tags
- List of posts with pictures, tags and author
- List of posts with pictures and tags, where the author is such and such
- List of posts with pictures and tags, where the author is such and such and tag such and such
- List of posts where the number of tags is more than 5, and the author's rating is less than 100, provided that in in records more than 1 picture.
In fact, it all rests on 1 request, "getting a list of records", with filtering and conditions.
However, to implement this using doctrine2, and probably bare SQL with PHP, is quite code-intensive.
Just in case, I will give here an example of a solution that I immediately refused. This is a separate method for each request, for example:
$this->recordRepository->findList($first, $offset);
$this->recordRepository->findListWithTags($first, $offset);
$this->recordRepository->findListWithTagsAndImages($first, $offset);
$this->recordRepository->findListWithTagsAndImagesAndAuthor($first, $offset);
$this->recordRepository->findListWithTagsAndImagesAndAuthor($first, $offset);
$this->recordRepository->findListWithTagsAndImagesAndAuthorByAuthor($first, $offset, $userId);
$this->recordRepository->findListWithTagsAndImagesAndAuthorByAuthorAndTag($first, $offset, $userId, $tagId);
...
$this->recordRepository->findListByCondition($condition);
Answer the question
In order to leave comments, you need to log in
as a possible tip, I can throw rikbruil/doctrine-specification happyr/doctrine-specification
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question