为什么DoctrineExtensions Blameable热切地抓取所有created_by用户 [英] Why is DoctrineExtensions Blameable eagerly fetching all created_by users

查看:170
本文介绍了为什么DoctrineExtensions Blameable热切地抓取所有created_by用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的用户类中使用以下特征

When using the following trait in my user class

/**
 * @var User
 *
 * @Gedmo\Blameable(on="create")
 * @ORM\ManyToOne(targetEntity="User")
 */
protected $createdBy;

/**
 * @var User
 *
 * @Gedmo\Blameable(on="update")
 * @ORM\ManyToOne(targetEntity="User")
 */
protected $updatedBy;

每当我查询用户时,也会获取createdBy用户,并递归递归。

Whenever i query a user the createdBy user is also fetched and this goes on recursively..

因此,如果由A创建的用户C是由A创建的,则会被查询。所有三个用户将被抓取...

So if user C that was created by B, that was created by A is queried. All three users will be fetched...

有没有办法禁用总是提取引用的用户?

Is there a way to disable always fetching the referenced user?

推荐答案

尝试更改您的ManyToOne声明以使用延迟加载:

try changing your ManyToOne declaration to use lazy loading:

* @ORM\ManyToOne(targetEntity="User", fetch="LAZY")

如同样的问题所述,当使用延迟加载时,您避免在初始查询中加入该数据,而仅在访问该属性时才查询该数据。
有什么区别?在fetch =EAGER之间并且获取=LAZY在教义中

As mentioned in a similar question, when using lazy loading you avoid joining that data in the initial query and instead will only query for it when the property is accessed. What is the difference between fetch="EAGER" and fetch="LAZY" in doctrine

这篇关于为什么DoctrineExtensions Blameable热切地抓取所有created_by用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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