1

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 Answers1

0

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

Community
  • 1
  • 1
Chase
  • 9,289
  • 5
  • 51
  • 77