title: many to many with self referencing how to correct join
body: <p>I have Category entity with many to many self referencing, and I want build simple query for selection all main categories, for that in raw query I just one time ineer joing table with many to many FK and add simple condition <code>csc.category_id = c0_ .id</code>. But I'm not undertand how to do it with query builder. I don't want use native query because I need Entity object classes and I don't want spent time for result set logic and I think doctrine should have exist solution, I just not found it</p>
  
  <pre><code>class Category
  
  /**
   * Many Users have many Users.
   * @ORM\ManyToMany(targetEntity="Category", mappedBy="subCategories", cascade={"persist"})
   * @ORM\Cache("NONSTRICT_READ_WRITE")
   */
  private $mainCategory;
  
  /**
   * @var CategoryConfigurations
   * @ORM\OneToOne(targetEntity="CategoryConfigurations", mappedBy="categoryId", cascade={"persist"})
   * @ORM\Cache("NONSTRICT_READ_WRITE")
   */
  private $categoryConfigurations;
  </code></pre>
  
  <p>my native query which return correct result 15 row.</p>
  
  <pre><code>SELECT DISTINCT c0_.id AS id_0
  
  FROM category c0_ 
  INNER JOIN category_sub_categories AS csc ON csc.category_id = c0_ .id
  WHERE c0_.custome_category = 't'
  </code></pre>
  
  <p>And my query builder example</p>
  
  <pre><code>    $queryBuilder
          -&gt;select('
              c
          ')
          -&gt;innerJoin('c.mainCategory', 'm')
          -&gt;where('m.id = c.id')
      ;
  </code></pre>
  
  <p>which return</p>
  
  <pre><code>SELECT c0_.id AS id_0, c0_.category_name AS category_name_1, c0_.custome_category AS custome_category_2, c0_.created_at AS created_at_3, c0_.updated_at AS updated_at_4 
  
  
  FROM category c0_ 
  
  INNER JOIN category_sub_categories c2_ ON c0_.id = c2_.sub_category_id 
  INNER JOIN category c1_ ON c1_.id = c2_.category_id 
  
  WHERE c1_.id = c0_.id
  </code></pre>
  
  <p>regarding this query I had zero instead 15 row. How to correct building query builder or DQL ?</p>