<?php
namespace Raltech\WarehouseBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
class Magazine
{
protected $id;
protected $name;
protected $description;
protected $wardrobe;
public function __construct()
{
$this->wardrobe = new ArrayCollection();
}
public function getId()
{
return $this->id;
}
public function setName($name)
{
$this->name = $name;
return $this;
}
public function getName()
{
return $this->name;
}
public function setDescription($description)
{
$this->description = $description;
return $this;
}
public function getDescription()
{
return $this->description;
}
public function addWardrobe(\Raltech\WarehouseBundle\Entity\Wardrobe $wardrobe)
{
$this->wardrobe[] = $wardrobe;
return $this;
}
public function removeWardrobe(\Raltech\WarehouseBundle\Entity\Wardrobe $wardrobe)
{
$this->wardrobe->removeElement($wardrobe);
}
public function getWardrobe()
{
return $this->wardrobe;
}
}
<?php
namespace Raltech\WarehouseBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
class Wardrobe
{
protected $id;
protected $name;
protected $description;
protected $magazine;
public function getId()
{
return $this->id;
}
public function setName($name)
{
$this->name = $name;
return $this;
}
public function getName()
{
return $this->name;
}
public function setDescription($description)
{
$this->description = $description;
return $this;
}
public function getDescription()
{
return $this->description;
}
public function setMagazine(\Raltech\WarehouseBundle\Entity\Magazine $magazine = null)
{
$this->magazine = $magazine;
return $this;
}
public function getMagazine()
{
return $this->magazine;
}
}
My 2 entites, I want to calculate how many Wardrobes are associated for each log, I have to do this from querybuilder
$em = $this->get('doctrine.orm.entity_manager');
$userRepository = $em->getRepository('Raltech\WarehouseBundle\Entity\Magazine');
$qb = $userRepository->createQueryBuilder('magazine')
->addSelect("magazine.id,magazine.name,magazine.description")
->InnerJoin('magazine.wardrobe', 'wardrobe')
->addSelect('COUNT(wardrobe.id) AS wardrobecount')
That didn't work, of course. So, can someone give me an example of how to read this from querybuilder?
source
share