title: Optimized Method that get comments count() of an article using doctrine2/Symfony
body: <p>I'am trying to find the best optimized way to get count of comments for each article</p>
  
  <p>I have two entities: Article &amp; Comment</p>
  
  <p>the Comment Entity have a field :</p>
  
  <pre><code>  /**
     * @ORM\ManyToOne(targetEntity="Easylist\ListmanagerBundle\Entity\Comment")
     * @ORM\JoinColumn(nullable=false)
     */
    private $comment;
  </code></pre>
  
  <p>So in my controller I want to Get All Article :</p>
  
  <pre><code> $em = $this-&gt;getDoctrine()-&gt;getEntityManager()
   $rep = $em-&gt;getRepository('ListmanagerBundle:Article');
   $all_Article = $rep-&gt;findAll();
  </code></pre>
  
  <p>I would like to have in the result of this query a field that contain the count of comments, like that :</p>
  
  <pre><code>array(
    "id"       =&gt;  "1",
    "Title"    =&gt; "Just a test",
    "nbr_coms" =&gt; "320"
  )
  </code></pre>
  
  <p>I thought to use a service but I found that services it's used in controller side not entities, like I thought to use the EntityManager into my Entity but it's not the Best way I think.</p>
  
  <p>I'm looking for an optimized solution, because we are talking about a millions article that each one have a millions of comments.</p>