Answer the question
In order to leave comments, you need to log in
Doctrine ORM does not recommend partial fetch, what are the alternatives?
If you limit the set of fields with a query, for example:
$em->createQuery("select u.id, u.name from MyApp\Domain\User u")->getResult();
$em->createQuery("select partial u.{id, name} from MyApp\Domain\User u")->getResult();
Answer the question
In order to leave comments, you need to log in
Is this not what you need? https://www.doctrine-project.org/projects/doctrine...
Why doesn't it work with join? In theory, there should be no restrictions in this aspect.
If you do not need all the fields or you want to optimize the query so that it does not necessarily pull out all, then it is better to build a separate query and pull out only the necessary data as data, and not as entities. Ultimately, nothing can prevent you from making a request for data in your custom repository and creating entities filled with this data. In most cases, after all, the contents of one row of the database does not increase the size of the sample as much as the number of rows of the sample itself. Those. select, conditionally, 20 lines with the texts of posts will most likely be faster than 10k posts without their texts.
If it is so important for you to choose entities, but not to choose field values (for example, each Post is a book for several megabytes of text, who knows?) - you can take the Post's text into a separate entity and use the `OneToOne` relation, then you will be able to take advantage of Doctrine's lazy loading of links and not select texts if they are not needed.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question