title: TypeORM: How to add COUNT field when using getMany()
body: <p>I have a scenario where I need to return some nested relational data as well as execute a COUNT on another relationship. As an example, I want to return Blogs with the array of Authors for the blog, and a COUNT of articles the blog contains:</p>
  <pre><code>[
    {
      id: 1,
      name: 'Blog 1',
      authors: [
        {
          id: 1,
          name: 'Author 1',
        },
        {
          id: 2,
          name: 'Author 2',
        },
      ],
      articleCount: 5,
    },
    {
      id: 2,
      name: 'Blog 2',
      authors: [
        {
          id: 2,
          name: 'Author 2',
        },
        {
          id: 3,
          name: 'Author 3',
        },
      ],
      articleCount: 2,
    },
  ];
  </code></pre>
  <p>I cannot seem to map the <code>articleCount</code> using <code>getMany()</code>, and <code>getRaw()</code> will not nest the authors.</p>
  <p>Is there a way to map the <code>articleCount</code> in the above, or possibly use <code>getRawMany</code> to nest the authors?</p>
  <p><strong>Example Entity:</strong></p>
  <pre><code>interface Blog {
    id: string;
    name: string;
    authors: Author[];
    articles: Article[];
    articleCount?: number; // field is not mapped to db column
  } 
  </code></pre>
  <p><strong>Query:</strong></p>
  <pre><code>const results = await repository.createQueryBuilder('blog')
    .select([
      'blog.id',
      'blog.name',
      'author.id',
      'author.name',
    ])
    .addSelect('COUNT(article.id)', 'blog_articleCount') // trying to map this to the entity
    .leftJoin('blog.authors', 'author')
    .leftJoin('blog.articles', 'article')
    .groupBy('blog.id')
    .addGroupBy('blog.name')
    .addGroupBy('author.id')
    .addGroupBy('author.name')
    .getMany();
  </code></pre>
  <p><strong>SQL:</strong></p>
  <pre><code>SELECT &quot;blog&quot;.&quot;id&quot; AS &quot;blog_id&quot;,
      &quot;blog&quot;.&quot;name&quot; AS &quot;blog_name&quot;,
      &quot;author&quot;.&quot;id&quot; AS &quot;author_id&quot;,
      &quot;author&quot;.&quot;name&quot; AS &quot;author_name&quot;,
      COUNT(&quot;article&quot;.&quot;id&quot;) AS &quot;blog_articleCount&quot;
  FROM &quot;blogs&quot; &quot;blog&quot;
  LEFT JOIN &quot;blog__authors&quot; &quot;blog_author&quot; ON &quot;blog_author&quot;.&quot;blogsId&quot; = &quot;blog&quot;.&quot;id&quot;
  LEFT JOIN &quot;authors&quot; &quot;author&quot; ON &quot;author&quot;.&quot;id&quot; = &quot;blog_author&quot;.&quot;authorsId&quot;
  LEFT JOIN &quot;articles&quot; &quot;article&quot; ON &quot;article&quot;.&quot;blog_id&quot; = &quot;blog&quot;.&quot;id&quot;
  GROUP BY &quot;blog&quot;.&quot;id&quot;,
      &quot;blog&quot;.&quot;name&quot;,
      &quot;author&quot;.&quot;id&quot;,
      &quot;author&quot;.&quot;name&quot;
  </code></pre>