title: Symfony/Doctrine relation COUNT in entity
body: <p>As the title states,</p>
  
  <p>I would like to run 1 query to get results from a table with the count of their respective relationships.</p>
  
  <p>Lets say I have a <code>Person</code> entity with a <em>OneToMany</em> relationship with a <code>Friend</code> entity</p>
  
  <p>The Person entity might look something like the following:</p>
  
  <pre><code>class Person
  {
      /**
       * @ORM\OneToMany(...)
       */
      protected $friends;
  
      public function __construct()
      {
          $this-&gt;friends = new ArrayCollection();
      }
  
      ...
  }
  </code></pre>
  
  <p>A classic SQL solution to what I want to achieve might look like the following:</p>
  
  <pre><code>SELECT p.*, COUNT(f.id) as friendsCount
  FROM Persons p
  LEFT JOIN Friends f
  ON f.person_id = p.id
  GROUP BY p.id
  </code></pre>
  
  <p>Now I am wondering if this could be done in DQL as well and storing the <em>count</em> value into the <code>Person</code> Entity</p>
  
  <p>Lets say I <em>expand</em> the <code>Person</code> entity like: (Keep in mind this is just an idea)</p>
  
  <pre><code>class Person
  {
      /**
       * @ORM\OneToMany(...)
       */
      protected $friends;
  
      protected $friendsCount;
  
      public method __construct()
      {
          $this-&gt;friends = new ArrayCollection();
      }
  
      ...
  
      public function getFriendsCount()
      {
          return $this-&gt;friendsCount;
      }
  }
  </code></pre>
  
  <p>Now I am having trouble finding how I could populate the count value in the entity from DQL:</p>
  
  <pre><code>SELECT p, /* What comes here ? */
  FROM AppBundle\Entity\Person p
  LEFT JOIN p.friends f
  GROUP BY p.id
  </code></pre>
  
  <p>PS: I do know I could just do:</p>
  
  <pre><code>$person-&gt;getFriends()-&gt;count();
  </code></pre>
  
  <p>And even mark it as extra lazy to get the count result.</p>
  
  <p>I just though this <em>count relationships</em> example demonstrated well what I am trying to do.</p>
  
  <p>(Which is populating the entity's non <code>@ORM\Column</code> properties from dql)</p>
  
  <p>Is this possible with Doctrine ?</p>
  
  <p>Is this breaking some solid principles ? (SRP ?)</p>
  
  <p>Cookie for your thoughs ;)</p>