title: Why is a many-to-many relation empty?
body: <p>I am building a website with a user authentified part, on Symfony 2.1.3, with Doctrine 2.
  Each user can be a member of a "usergroup", and each usergroup can contains many users.</p>
  
  <p>So it is a many-to-many relation.</p>
  
  <p>I follow the security tutorial to authentify my users, and it works perfectly.
  <a href="http://symfony.com/doc/current/cookbook/security/entity_provider.html" rel="nofollow">http://symfony.com/doc/current/cookbook/security/entity_provider.html</a></p>
  
  <p>The passwords are encoded; the database relation works fine.</p>
  
  <p>I have got a service, that handle the "LoginSuccess" event, and add the user to the session.
  I think it works correctly, because I find my users properties in my parent front controller.</p>
  
  <pre><code>public function onAuthenticationSuccess(Request $request, TokenInterface $token)
  {
      $session = $request-&gt;getSession();
  
      $session-&gt;set('_user', $token-&gt;getUser());
  
      if ($session-&gt;has('referer')) {
          if (($session-&gt;get('referer') !== null) &amp;&amp; ($session-&gt;get('referer') !== '')) {
              $response = new RedirectResponse($session-&gt;get('referer'));
          } else {
              $response = new RedirectResponse($request-&gt;getBaseUrl() . '/');
          }
      } else {
          // if no referer then go to homepage
          $response = new RedirectResponse($request-&gt;getBaseUrl() . '/');
      }
  
      return $response;
  }
  </code></pre>
  
  <p>But now, I want to get the groups of the authentified current user, and it give me an empty array...</p>
  
  <pre><code>// Somewhere in a controller action.
  $session = $this-&gt;getRequest()-&gt;getSession();
  $current_user = $session-&gt;get('_user');
  echo '&lt;pre&gt;';
  exit(var_dump($current_user));
  object(Me\MyProject\CoreBundle\Entity\User)#38 (16) {
      [...]
      ["groups":"Me\MyProject\CoreBundle\Entity\User":private] =&gt; object(Doctrine\ORM\PersistentCollection)#34 (9) {
          ["snapshot":"Doctrine\ORM\PersistentCollection":private] =&gt; array(0) {
  
          }
          ["owner":"Doctrine\ORM\PersistentCollection":private] =&gt; NULL
          ["association":"Doctrine\ORM\PersistentCollection":private] =&gt; NULL
          ["em":"Doctrine\ORM\PersistentCollection":private] =&gt; NULL
          ["backRefFieldName":"Doctrine\ORM\PersistentCollection":private] =&gt; NULL
          ["typeClass":"Doctrine\ORM\PersistentCollection":private] =&gt; NULL
          ["isDirty":"Doctrine\ORM\PersistentCollection":private] =&gt; bool(false)
          ["initialized":"Doctrine\ORM\PersistentCollection":private] =&gt; bool(false)
          ["coll":"Doctrine\ORM\PersistentCollection":private] =&gt; object(Doctrine\Common\Collections\ArrayCollection)#33 (1) {
              ["_elements":"Doctrine\Common\Collections\ArrayCollection":private] =&gt; array(0) {
  
              }
          }
      }
  }
  </code></pre>
  
  <p>I want the user to access some features depending on his group(s)... So It is really bad for me not to get these groups.
  Any idea ?</p>
  
  <p>My yml model configuration file :</p>
  
  <pre><code>Me\MyProject\CoreBundle\Entity\User:
  type: entity
  repositoryClass: FSB\Intranet\CoreBundle\Repository\UserRepository
  table: users
  fields:
      id:
          id: true
          type: integer
          unsigned: false
          nullable: false
          generator:
              strategy: IDENTITY
  [...]
  manyToMany:
      groups:
          targetEntity: Usergroup
          inversedBy: users
          joinTable:
              name: usergroups_for_user
              joinColumns:
                  user_id:
                      referencedColumnName: id
              inverseJoinColumns:
                  usergroup_id:
                      referencedColumnName: id
  lifecycleCallbacks: {  }
  </code></pre>