I perform a simple query like this, but loose all the objects that do not have an association with episodes:
$query = $this->getEntityManager()
->createQuery('
SELECT p,e
FROM AcmeDemoBundle:Place p
JOIN p.episodes e
WHERE p.id = :id'
)
->setParameter('id',$id);
This is a simple asso:
/**
* @ORM\OneToMany(targetEntity="Episode", mappedBy="place")
*/
protected $episodes;
My query automatically discards the objects that have an empty $episodes Collection. Does anyone know why? I am sure it makes sense but I can’t figure this out.
Is there a way to fetch the object anyway whether there is or there is not the asso episodes?
Many thanks.
I think you want a
LEFT JOINinstead of just aJOIN.JOIN gives only records from the left that also have a record on the right.
LEFT JOIN gives records from the left regardless of if they also have a record on the right.