title: Doctrine Query builder, count related one to many rows
body: <pre><code>&lt;?php
  namespace Raltech\WarehouseBundle\Entity;
  
  use Doctrine\ORM\Mapping as ORM;
  use Doctrine\Common\Collections\ArrayCollection;
  
  /**
   * @ORM\Entity
   * @ORM\Table(name="warehouse_magazine")
   */
  class Magazine
  {
      /**
       * @ORM\Column(type="integer")
       * @ORM\Id
       * @ORM\GeneratedValue(strategy="AUTO")
       */
      protected $id;
  
      /**
       * @ORM\Column(type="string", length=100)
       */
      protected $name;
  
  
      /**
       * @ORM\Column(type="text")
       */
      protected $description;
  
  
      /**
       * @ORM\OneToMany(targetEntity="Wardrobe", mappedBy="magazine",cascade={"remove"})
      */
      protected $wardrobe;
  
  
      public function __construct()
      {
          $this-&gt;wardrobe = new ArrayCollection();
      }
  
      /**
       * Get id
       *
       * @return integer 
       */
      public function getId()
      {
          return $this-&gt;id;
      }
  
      /**
       * Set name
       *
       * @param string $name
       * @return Magazine
       */
      public function setName($name)
      {
          $this-&gt;name = $name;
  
          return $this;
      }
  
      /**
       * Get name
       *
       * @return string 
       */
      public function getName()
      {
          return $this-&gt;name;
      }
  
      /**
       * Set description
       *
       * @param string $description
       * @return Magazine
       */
      public function setDescription($description)
      {
          $this-&gt;description = $description;
  
          return $this;
      }
  
      /**
       * Get description
       *
       * @return string 
       */
      public function getDescription()
      {
          return $this-&gt;description;
      }
  
      /**
       * Add wardrobe
       *
       * @param \Raltech\WarehouseBundle\Entity\Wardrobe $wardrobe
       * @return Magazine
       */
      public function addWardrobe(\Raltech\WarehouseBundle\Entity\Wardrobe $wardrobe)
      {
          $this-&gt;wardrobe[] = $wardrobe;
  
          return $this;
      }
  
      /**
       * Remove wardrobe
       *
       * @param \Raltech\WarehouseBundle\Entity\Wardrobe $wardrobe
       */
      public function removeWardrobe(\Raltech\WarehouseBundle\Entity\Wardrobe $wardrobe)
      {
          $this-&gt;wardrobe-&gt;removeElement($wardrobe);
      }
  
      /**
       * Get wardrobe
       *
       * @return \Doctrine\Common\Collections\Collection 
       */
      public function getWardrobe()
      {
          return $this-&gt;wardrobe;
      }
  }
  
  
  &lt;?php
  namespace Raltech\WarehouseBundle\Entity;
  
  use Doctrine\ORM\Mapping as ORM;
  
  /**
   * @ORM\Entity
   * @ORM\Table(name="warehouse_wardrobe")
   */
  class Wardrobe
  {
      /**
       * @ORM\Column(type="integer")
       * @ORM\Id
       * @ORM\GeneratedValue(strategy="AUTO")
       */
      protected $id;
  
      /**
       * @ORM\Column(type="string", length=100)
       */
      protected $name;
  
  
      /**
       * @ORM\Column(type="text")
       */
      protected $description;
  
  
      /**
       * @ORM\ManyToOne(targetEntity="Magazine", inversedBy="wardrobe")
       * @ORM\JoinColumn(name="magazine_id", referencedColumnName="id")
       */
      protected $magazine;
  
      /**
       * Get id
       *
       * @return integer 
       */
      public function getId()
      {
          return $this-&gt;id;
      }
  
      /**
       * Set name
       *
       * @param string $name
       * @return Wardrobe
       */
      public function setName($name)
      {
          $this-&gt;name = $name;
  
          return $this;
      }
  
      /**
       * Get name
       *
       * @return string 
       */
      public function getName()
      {
          return $this-&gt;name;
      }
  
      /**
       * Set description
       *
       * @param string $description
       * @return Wardrobe
       */
      public function setDescription($description)
      {
          $this-&gt;description = $description;
  
          return $this;
      }
  
      /**
       * Get description
       *
       * @return string 
       */
      public function getDescription()
      {
          return $this-&gt;description;
      }
  
      /**
       * Set magazine
       *
       * @param \Raltech\WarehouseBundle\Entity\Magazine $magazine
       * @return Wardrobe
       */
      public function setMagazine(\Raltech\WarehouseBundle\Entity\Magazine $magazine = null)
      {
          $this-&gt;magazine = $magazine;
  
          return $this;
      }
  
      /**
       * Get magazine
       *
       * @return \Raltech\WarehouseBundle\Entity\Magazine 
       */
      public function getMagazine()
      {
          return $this-&gt;magazine;
      }
  }
  </code></pre>
  
  <p>My 2 entites, i want count how many Wardrobes is related for each magazines, i must make this from querybuilder</p>
  
  <pre><code>$em = $this-&gt;get('doctrine.orm.entity_manager');
  $userRepository = $em-&gt;getRepository('Raltech\WarehouseBundle\Entity\Magazine');
  $qb = $userRepository-&gt;createQueryBuilder('magazine')
      -&gt;addSelect("magazine.id,magazine.name,magazine.description")
      -&gt;InnerJoin('magazine.wardrobe', 'wardrobe')
      -&gt;addSelect('COUNT(wardrobe.id) AS wardrobecount')
  </code></pre>
  
  <p>This didn't work of course.
  So, somebody can me provide example how to count this from querybuilder?</p>