title: How to JOIN without relational table in Symfony Doctrine with QueryBuilder between 2 entities
body: <p>I have an Entity Video related with a Entity Category and I need to run this SQL with Doctrine QueryBuilder, with this I can get the most used categories in all videos (1000+):</p>
  
  <pre><code>    SELECT c.*
      FROM Video v
      INNER JOIN video_category vc ON vc.video_id = v.id
      INNER JOIN Category c ON vc.category_id = c.id
      GROUP BY c.id
      HAVING COUNT(v.id) &gt; 1000
      ORDER BY c.name ASC;
  </code></pre>
  
  <p>My querybuilder:</p>
  
  <pre><code>    $queryBuilder = $this-&gt;getEntityManager()
          -&gt;createQueryBuilder()
          -&gt;select('c')
          -&gt;from('AcmeVideoBundle:Video', 'v')
          // Can Doctrine join itself silently with relational info in the Entities?
          -&gt;join('AcmeCategoryBundle:Category', 'c', Expr\Join::WITH, 'v.id = c.id')
          -&gt;groupBy('c.id')
          -&gt;having('COUNT(v.id) &gt; 1000')
          -&gt;orderBy('c.name', 'ASC')
          -&gt;getQuery();
  </code></pre>
  
  <p>But the SQL query output by queryBuilder is this:</p>
  
  <pre><code>    SELECT c0_.id AS id0, c0_.NAME AS name1 
      FROM Video v1_ 
      INNER JOIN Category c0_ ON (v1_.id = c0_.id) 
      GROUP BY c0_.id 
      HAVING COUNT(v1_.id) &gt; 1000
      ORDER BY c0_.NAME ASC
  </code></pre>
  
  <p>Without the relational table (video_category)</p>
  
  <p>The Entities mapping:</p>
  
  <pre><code>    /**
       * Video
       *
       * @ORM\Table
       * @ORM\Entity(repositoryClass="Acme\VideoBundle\Entity\VideoRepository")
       */
      class Video
      {
          /**
           * @ORM\Id
           * @ORM\Column(type="integer")
           * @ORM\GeneratedValue(strategy="AUTO")
           */
          private $id;
  
          /**
           * @ORM\ManyToMany(targetEntity="Acme\CategoryBundle\Entity\Category", cascade={"persist"})
           */
          private $category;
  
          // More fields, getters and setters etc...
      }
  
      /**
       * Category
       *
       * @ORM\Table
       * @ORM\Entity(repositoryClass="Acme\CategoryBundle\Entity\CategoryRepository")
       */
      class Category
      {
          /**
           * @ORM\Id
           * @ORM\Column(type="integer")
           * @ORM\GeneratedValue(strategy="AUTO")
           */
          private $id;
  
          /**
           * @ORM\Column(type="string", length=255)
           */
          private $name;
  
          // More fields, getters and setters etc...
      }
  </code></pre>
  
  <p>How can I use the relation table to run the original SQL query with doctrine Querybuilder? I missed something?</p>
  
  <p>INFO: When I findBy{field}, persist, flush, clear on all entities works fine, the Doctrine relations are ok, I have a Video, Category and video_category tables fine, the original SQL query works perfect.</p>