Doctrine preLoad监听器在执行之前操纵QueryBuilder [英] Doctrine preLoad Listener to Manipulate QueryBuilder before Execution

查看:90
本文介绍了Doctrine preLoad监听器在执行之前操纵QueryBuilder的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在查询发送到数据库之前,有没有办法操纵Doctrine 2.6 QueryBuilder(DQL)?

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.

但是,教义没有一个 preLoad监听器 ...

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

推荐答案

您可以以另一种方式实现您的目标。您可以设置在注释中提取实体的渴望模式:

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

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

您还需要什么 preLoad listener?

For what else do you need preLoad listener?

如果要在执行之前修改每个生成的SQL,您可以使用 SQL过滤器

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

这篇关于Doctrine preLoad监听器在执行之前操纵QueryBuilder的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆