Doctrine preLoad Listener to Manipulate QueryBuild

2019-08-17 03:23发布

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条回答
我只想做你的唯一
2楼-- · 2019-08-17 04:10

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.

查看更多
登录 后发表回答