I try to get all my objects DemandCab with their children object (DecisionCab).
My 2 entities
/**
* DemandCab.
*
* @ORM\Table()
* @ORM\Entity(repositoryClass="DemandCabRepository")
*/
class DemandCab
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var DecisionCab
*
* @ORM\OneToMany(targetEntity="\My\CabBundle\Entity\DecisionCab", mappedBy="demandCab")
*/
private $decisionsCab;
/**
* @var \DateTime
*
* @ORM\Column(name="startDate", type="datetime")
*/
private $startDate;
/**
* @var \DateTime
*
* @ORM\Column(name="endDate", type="datetime", nullable=true)
*/
private $endDate;
/**
* @var int
*
* @ORM\Column(name="followup", type="integer", nullable=true)
*/
private $followup;
/**
* @var InfoCab
*
* @ORM\ManyToOne(targetEntity="\My\CabBundle\Entity\InfoCab", inversedBy="demandsCab")
*/
private $infoCab;
}
/**
* DecisionCab.
*
* @ORM\Table()
* @ORM\Entity(repositoryClass="DecisionCabRepository")
*/
class DecisionCab
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var DemandCab
*
* @ORM\ManyToOne(targetEntity="\My\CabBundle\Entity\DemandCab", inversedBy="decisionsCab")
*/
private $demandCab;
/**
* @var bool
*
* @ORM\Column(name="decision", type="boolean", nullable=true)
*/
private $decision;
/**
* @var string
*
* @ORM\Column(name="motif", type="string", length=500, nullable=true)
*/
private $motif;
/**
* @var string
*
* @ORM\Column(name="role", type="string", length=255)
*/
private $role;
/**
* @var \DateTime
*
* @ORM\Column(name="date", type="datetime", nullable=true)
*/
private $date;
/**
* @var DemandCab
*
* @ORM\ManyToOne(targetEntity="\My\CabBundle\Entity\DemandCab", inversedBy="decisionsCab")
*/
private $demandCab;
/**
* @var User
*
* @ORM\ManyToOne(targetEntity="\My\CabBundle\Entity\User", inversedBy="decisionsCab")
*/
private $user;
}
In my DemandCabRepository
public function findAllCompleted(){
$qb = $this->createQueryBuilder("dem");
$qb->select('dem, dec');
$qb->leftJoin("dem.decisionsCab", "dec");
$qb->andWhere("dem.completed = 1");
$qb->orderBy("dem.startDate", "DESC");
return $qb->getQuery()->getResult();
}
My DemandCab data
My DecisionCab data
When i dump result, only 2 decisions appear ...
... whereas when i use getArrayResult
, i have my 4 decisions ...
The query is good but i dont understand why hydration remove DecisionCab object with attribute decision
at 0 or 1 (only null are display).
I would like to understand why and is there a solution to get DemandCab object with all DecisionCab children object.
Thanks