title: How to get doctrine2 table alias?
body: <p>I want to create a method in my a Doctrine2 repository class that takes a QueryBuilder and adds some extra clauses, one of which is an inner join.</p>
  
  <p>How can I find out the table alias that was used to instantiate the querybuilder? Is this something discoverable or should it be a convention across the codebase (and therefore a potential source of bugs)?</p>
  
  <p>My client code is:</p>
  
  <pre><code>public function getPasswordAction($id)
  {
      $user = $this-&gt;get('security.context')-&gt;getToken()-&gt;getUser();
  
      $repository = $this-&gt;getDoctrine()
          -&gt;getRepository('TenKPwLockerBundle:Password');
  
      $query = $repository-&gt;createQueryBuilder('p')
          -&gt;where('id = :id')
          -&gt;setParameter('id', $id);
  
      $query = $repository-&gt;userCanReadRestriction($query, $user);
      ...
  </code></pre>
  
  <p>and my repository class contains:</p>
  
  <pre><code>public function userCanReadRestriction(\Doctrine\ORM\QueryBuilder $builder, \TenK\UserBundle\Entity\User $user)
  {
                               // where can I get 'p' from?
      return $builder-&gt;innerJoin('p.shares', 's')
          -&gt;where('createdBy = :creator')
          -&gt;orWhere('s.toUser = :toId')
          -&gt;setParameters(array('creator' =&gt; $user, 'toUser' =&gt; $user));
  }
  </code></pre>
  
  <p>In fact, in the above code, how can I confirm that the QueryBuilder is working with the Password Entity at all?</p>