title: Avoid lazy loading Doctrine Symfony2
body: <p>I have two entities in my project : User and Avatar.</p>
  
  <p>User owns Avatar with a OneToOne relation.</p>
  
  <p>Avatar is an entity with a file object and a fileName. It uses @ORM\HasLifecycleCallbacks to save the file or to remove it as described in the <a href="http://symfony.com/doc/current/cookbook/doctrine/file_uploads.html#using-lifecycle-callbacks" rel="nofollow noreferrer">Symfony2 documentation</a>.</p>
  
  <p>In my controller, I want to remove the Avatar entity from the current user (I use <code>$user = $this-&gt;get('security.context')-&gt;getToken()-&gt;getUser()</code>), but I can't get to the avatar with <code>$user-&gt;getAvatar()</code> :</p>
  
  <pre><code>var_dump($user-&gt;getAvatar());
  
  object(AppBundle\Entity\Avatar)
      private 'id' =&gt; int 20
      public 'file' =&gt; null
      private 'fileName' =&gt; null
  </code></pre>
  
  <p>But if I try to acces the avatar's fileName, it gets returned :</p>
  
  <pre><code>$filename = $user-&gt;getAvatar()-&gt;getFileName();
  var_dump($user-&gt;getAvatar());
  
  object(AppBundle\Entity\Avatar)
      private 'id' =&gt; int 20
      public 'file' =&gt; null
      private 'fileName' =&gt; string 'myfile.png'
  </code></pre>
  
  <p>How can I get the Avatar associated with my user ?</p>