G
G
grabbee2017-07-26 16:40:03
Doctrine ORM
grabbee, 2017-07-26 16:40:03

How to request multiple Posts along with tags in Doctrine/Symfony?

Like a standard situation. But failed to implement. There are three tables

Table_Posts (post_id, text, other_data)
Table_Tags (tag_id, title, other_data)
Table_Posts_Tags (post_id, tag_id)

I try to get 15 posts along with a list of tags for each, I get 16 requests :(
1. One for getting posts
2. And 15 for a list of tags for each
Is this normal? .. Is everyone like this?)
How to do it right?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Viktor, 2017-07-26
@TexElless

Not for everyone :)
It is necessary either to add a mode for the relationship. fetch="EAGER"
Or, if it is not always necessary to load tags, to load a post with tags, make a separate method in the repository in which JOIN will be performed.
fetch mode documentation

D
Dmitry MiksIr, 2017-07-26
@miksir

Try using the paginator
docs.doctrine-project.org/projects/doctrine-orm/en...
Or you can do it yourself in the repository.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question