Currently this function works : it displays for a specific game, how many jobs there are.
The problem : If there is no job, the game does not appear on the list.
How to display the game even if there is no job attached ?
Thanks
public function getWithGames()
{
$q = $this->createQuery('c')
->leftJoin('c.stJob j')
->where('j.expires_at > ?', date('Y-m-d h:i:s', time()))
->addOrderBy('c.name');
$q->andWhere('j.is_activated = ?', 1);
$q->andWhere('j.is_public = ?', 1);
return $q->execute();
}
Your conditions should be part of the LEFT JOIN … ON clause.
Putting conditions in the
ONclause (as opposed to theWHERE) indicates that they apply specifically to theJOIN. If no rows satisfy those conditions, there is no join — and that’s just what you want in this case. Putting them in theWHEREindicates that the result rows must satisfy those conditions. And obviously if there was no join, you can’t satisfy any conditions about thejtable.