Symfony2 and Doctrine2 - QueryBuilder with relational entities

给你一囗甜甜゛ 提交于 2019-12-06 04:17:36

Default behaviour does not load related entities' fields for performance reasons, it only provides a proxy class of those relations with OBJECT hydratation (that is default hydratation mode).

You have to state the JOIN as you well did.

EDIT: When you do $p->getSection()->getName() from a Controller or p.section.name from a Twig template, without having stated the JOIN in the query (with default QueryBuilder), Doctrine requests missing informations of the relation at this time. That could be very heavy if you do that in a loop, like in a list display... So try to load what you need from relations at first request ;)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!