title: Doctrine 2 Self Join Query
body: <p>I'm still pretty new to Doctrine and I'm trying to retrieve a suggest list of users to follow.</p>
  
  <p>So basically, given an user A, I need to select all users that are followed by the users that user A follow, excluding users that user A already follow.</p>
  
  <p>How could I do that with Doctrine query builder ?</p>
  
  <pre><code>class User
  {
  
  ...
  
  /**
   * @ORM\ManyToMany(targetEntity="User", inversedBy="followees")
   * @ORM\JoinTable(name="user_followers",
   *      joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id", onDelete="CASCADE")},
   *      inverseJoinColumns={@ORM\JoinColumn(name="follower_id", referencedColumnName="id", onDelete="CASCADE")}
   *      )
   */
  private $followers;
  
  /**
   * @ORM\ManyToMany(targetEntity="User", mappedBy="followers")
   */
  private $followees;
  }
  </code></pre>
  
  <p><strong>EDIT</strong>: According to slaur4 solution, I tried this</p>
  
  <pre><code>    $qb = $this-&gt;createQueryBuilder('u');
  
      $qb-&gt;select('suggestions')
      -&gt;join('u.followees', 'followees')
      -&gt;join('followees.followers', 'suggestions')
      -&gt;where('u.id = :id')
      -&gt;andWhere($qb-&gt;expr()-&gt;notIn('suggestions.id', 'u.followees'))
      -&gt;setParameter('id', $user-&gt;getId());
  </code></pre>
  
  <p>But it gives me the following exception: </p>
  
  <pre><code>QueryException: [Syntax Error] line 0, col 171: Error: Expected Literal, got 'u'
  </code></pre>