Doctrine preLoad Listener to Manipulate QueryBuilder before Execution

删除回忆录丶 提交于 2019-12-13 08:49:08

问题


Is there a way to manipulate a Doctrine 2.6 QueryBuilder (DQL) before the query is sent to the database?

So for example, if we always want two entities to be associated (without lazy loading) then we need to JOIN the other entity's table (for efficiency). So it would be great if we could check if the other entity was joined yet, and if not, join it automatically.

But doctrine doesn't have a preLoad listener...


回答1:


You can achieve your goal another way. You can set eager mode for fetching entities in annotations:

/**
 * @ORM\ManyToOne(..., fetch="EAGER")
 */

For what else do you need preLoad listener?

If you want just modify every generated SQL before it will be executed you can use SQL Filters.



来源:https://stackoverflow.com/questions/33485360/doctrine-preload-listener-to-manipulate-querybuilder-before-execution

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