title: Symfony Query Builder partial query throwing circular reference error
body: <p>In my Symfony 4 application there is an API endpoint from which I need information about last <code>Post</code> from a given <code>Thread</code> and <code>Author</code> of this particular <code>Post</code>.
  This should be the structure of a reponse</p>
  
  <pre><code>lastPost: {
    id: 1,
    createdAt: 2018-04-30
    author: {
      id: 1
      nick: 'admin
    }
  </code></pre>
  
  <p>I tried to return this from a repository method in my <code>PostRepository</code> using <code>$this-&gt;json-&gt;($response)</code>.</p>
  
  <pre><code>public function findLastPostByThreadId($threadId)
      {
          return $this-&gt;createQueryBuilder('p')
              -&gt;select('p.id, p.createdAt')
              -&gt;addSelect('author.id, author.nick')
              -&gt;innerJoin('p.author', 'author')
              -&gt;where('p.thread = :threadId')
              -&gt;setParameter('threadId', $threadId)
              -&gt;orderBy('p.createdAt', 'DESC')
              -&gt;setMaxResults(1)
              -&gt;getQuery()
              -&gt;getOneOrNullResult();
      }
  </code></pre>
  
  <p>But if I do that, the <code>post.id</code> field gets overwritten by <code>author.id</code> and response doesn't have a required structure.</p>
  
  <p>Then I've tried to rewrite this query to partial objects query:</p>
  
  <pre><code>public function findLastPostByThreadId($threadId)
      {
          return $this-&gt;createQueryBuilder('p')
              -&gt;select('p.id, p.createdAt')
              -&gt;addSelect('partial author.{id, nick}')
              -&gt;innerJoin('p.author', 'author')
              -&gt;where('p.thread = :threadId')
              -&gt;setParameter('threadId', $threadId)
              -&gt;orderBy('p.createdAt', 'DESC')
              -&gt;setMaxResults(1)
              -&gt;getQuery()
              -&gt;getOneOrNullResult();
      }
  </code></pre>
  
  <p>But then it throws error <code>Cannot select entity through identification variables without choosing at least one root entity alias.</code></p>
  
  <p>When I try to make this query based entirely on partial objects</p>
  
  <pre><code>public function findLastPostByThreadId($threadId)
  {
      return $this-&gt;createQueryBuilder('p')
          -&gt;select('partial p.{id, createdAt}')
          -&gt;addSelect('partial author.{id, nick}')
          -&gt;innerJoin('p.author', 'author')
          -&gt;where('p.thread = :threadId')
          -&gt;setParameter('threadId', $threadId)
          -&gt;orderBy('p.createdAt', 'DESC')
          -&gt;setMaxResults(1)
          -&gt;getQuery()
          -&gt;getOneOrNullResult();
  }
  </code></pre>
  
  <p>I get 
  <code>Uncaught Exception: A circular reference has been detected when serializing the object of class "App\Entity\Section" (configured limit: 1)</code> even if I don't query for <code>Section</code> entity. Section is in one-to-many relation with Thread and I am not requesting any information from this, so I honestly have no idea where this is coming from.</p>
  
  <p>I feel like I'm missing something here or my approach to this is wrong. I guess I could use repository method of <code>Author</code> entity to get author details from given post and build a response from it but perhaps there is a way to get this data in single query?</p>