I have an entity named PointsComptage.php
and another one named Compteurs.php
.
This is the relations between them:
// Compteurs.php
/**
* @var \PointsComptage
*
* @ORM\ManyToOne(targetEntity="PointsComptage", inversedBy="compteurs")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="pointscomptage_id", referencedColumnName="id")
* })
*/
private $pointsComptage;
/**
* @var \Doctrine\Common\Collections\Collection
*
* @ORM\OneToMany(targetEntity="ParametresMesure", mappedBy="compteurs")
*/
private $parametresMesure;
/* ... */
// PointsComptage.php
/**
* @var \Doctrine\Common\Collections\Collection
*
* @ORM\OneToMany(targetEntity="Compteurs", mappedBy="pointsComptage")
*/
private $compteurs;
/* ... */
This is the query in my repository entity to recover the compteurs with their attributes for one pointComptage:
$queryBuilder = $this->_em->createQueryBuilder();
$queryBuilder
->select ('c')
->from('MySpaceMyBundle:Compteurs', 'c')
->leftJoin('c.pointsComptage', 'pc')
->join('c.parametresMesure', 'pm')
->join('pm.typesUnite', 'tu')
->join('pm.typesParametre', 'tp')
->where('c.pointsComptage = pc.id')
->andWhere('pm.compteurs = c.id')
->andWhere('pm.typesUnite = tu.id')
->andWhere('pm.typesParametre = tp.id')
->andWhere('c.pointsComptage = :id')
->add('orderBy', 'c.miseEnService', 'ASC')
->setParameter('id', $id);
return $queryBuilder->getQuery()
->getResult();
The problem is that I recover well my compteurs for the pointComptage selected, but only the compteurs which have parametresMesure relation.
In my database, it's possible that a compteur have not parametreMesure datas.
How can I recover the compteurs which have not parametresMesure and the compteurs which have parametresMesure attributes (in the same queryBuilder)?
I read on the doctrine documentation that a leftJoin in a queryBuilder works like a outer join.
That I am trying to do, is to recover all the compteurs
linked to the pointComptage
selected, whether or not the parametresMesure
.
leftJoin
instead ofjoin
– FalsterleftJoin
insteadjoin
in my queryBuilder, my request returns me the same results, i-e just the compteurs which have parametresMesure, but I have well a compteur with no parametresMesure for the pointComptage selected before. – Mease