title: doctrine orm count 1:n relationship on join
body: <p>I am using doctrine orm with admingenerator module from symfony2 and I am unable to do a select count involving two tables. 
  <strong>I would really appreciate any thoughts on this. Thanks a lot in advance!</strong></p>
  
  <p>This is the <strong>querybuilder</strong> expression: </p>
  
  <pre><code>class ListController extends BaseListController
  {
  protected function getQuery()
      {
          $query = $this-&gt;getDoctrine()
                      -&gt;getEntityManager()
                      -&gt;createQueryBuilder()
                      -&gt;select('q, count(f.fbid) AS no')
                      -&gt;from('Shlomi\UsersBundle\Entity\users', 'q')
                      -&gt;leftJoin('q.fbid' , 'f')
                      -&gt;groupBy('q.fbid');
  
  
          $this-&gt;processSort($query);
          $this-&gt;processFilters($query);
                  $this-&gt;processScopes($query);
  
          return $query-&gt;getQuery();
      }
  }
  </code></pre>
  
  <p>The two entities I am using are: </p>
  
  <pre><code>class Users
  {
      /**
       * @var integer $id
       *
       * @ORM\Column(name="id", type="integer", nullable=false)
       * @ORM\Id
       * @ORM\GeneratedValue(strategy="IDENTITY")
       */
      private $id;
  
      /**
       * @var bigint $fbid
       *
       * @ORM\OneToMany(targetEntity="Friendships", mappedBy ="fbid")
       * @ORM\JoinColumns({
       *   @ORM\JoinColumn(name="fbid", referencedColumnName="fbid")
       * })
       */
      private $fbid;
     ....
  </code></pre>
  
  <p>AND </p>
  
  <pre><code>class Friendships
  {
      /**
       * @var integer $Id
       *
       * @ORM\Column(name="id", type="integer", nullable=false)
       * @ORM\Id
       * @ORM\GeneratedValue(strategy="IDENTITY")
       */
      private $Id;
  
     /**
       * @var Users
       *
       * @ORM\ManyToOne(targetEntity="Users", inversedBy="fbid")
       * @ORM\JoinColumns({
       *   @ORM\JoinColumn(name="fbid", referencedColumnName="fbid")
       * })
       */
      private $fbid;
  ....
  </code></pre>
  
  <p>Whereas the association annotation in Friendships has been automatically generated by doctrine:generate-entities (containing a foreign key reference of fbid from Users.fbid) the annotation in Users(1:n) has been inserted manually to best of my knowledge. </p>
  
  <p>I have tried editing the query builder and annotation over and over again but in the end i get this :</p>
  
  <blockquote>
    <p>An exception has been thrown during the rendering of a template ("Catchable Fatal Error: Object of class Doctrine\ORM\PersistentCollection could not be converted to string in C:\xampp\htdocs\symfony2\app\cache\dev\twig\ea\85\2b678090e942db52cc01e3950dbc.php line 225") in Admingenerated/ShlomiUsersBundle/Resources/views/UsersList/index.html.twig at line 92.</p>
  </blockquote>
  
  <p>Thanks,
  ion</p>