title: How to create a query in the entity repository with a many-to-many relationship? Empty query
body: <p>I have got a many-to-many relationship between advert and document : here are the 3 tables :</p>
  
  <p>advert<br>
  document<br>
  document_advert.      </p>
  
  <p>How can I get the <code>author</code> from Advert and the <code>path</code> from Document? 
  The first attempt does not throw any error, but the query seems empty, I don't understand this from the debugger :</p>
  
  <p>[![enter image description here][1]][1]</p>
  
  <p>[![enter image description here][2]][2]</p>
  
  <p>My goal is something like this in sql :</p>
  
  <pre><code>SELECT d.path, a.author 
  FROM document_advert da 
  JOIN document d 
  JOIN advert a 
  WHERE da.advert_id = 1 
  AND da.document_id = d.id
  </code></pre>
  
  <p>My attempt (I am in the AdvertRepository) :</p>
  
  <pre><code>public function getDocNames($id){
       $em = $this-&gt;getEntityManager();
  
      $query = $this-&gt;createQueryBuilder('a')
              -&gt;join('a.document', 'd')
              -&gt;addSelect('d')
              -&gt;where("a.id = :id")
              -&gt;setParameter('id', $id)
              -&gt;getQuery()
      ;
      return $query-&gt;getResult();
      //issue: empty query
  
  }
  </code></pre>
  
  <hr>
  
  <p>EDIT : I am trying to get all the values from <code>d</code>, without calling them explicitly (I don't want to do <code>d.path, d.name, etc.</code> but <code>d</code> instead). But ".path" in the twig file is not recognized if I don't add "d.path" in the query.</p>
  
  <p>in twig:</p>
  
  <pre><code>{% for doc in docNames %}
      {{ doc.path }}
  {% endfor %}
  </code></pre>
  
  <p>If I remove <code>.path</code> in the query, ".path" "does not exist " : here is the query in the DQL format :</p>
  
  <pre><code>public function getDocNamesC($id){
          $query = $this-&gt;_em-&gt;createQuery("SELECT a, d.path FROM OCPlatformBundle:Advert a JOIN a.documents d WHERE a.id = $id");
          return $query-&gt;getResult();
      }
  </code></pre>