Why is DoctrineExtensions Blameable eagerly fetching all created_by users

浪子不回头ぞ 提交于 2019-12-11 13:28:52

问题


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;

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

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?


回答1:


try changing your ManyToOne declaration to use lazy loading:

* @ORM\ManyToOne(targetEntity="User", fetch="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



来源:https://stackoverflow.com/questions/37123506/why-is-doctrineextensions-blameable-eagerly-fetching-all-created-by-users

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