One trick is to build two queries, and then use getDQL () to feed the first query into the second query.
For example, this query returns a separate list of game identifiers:
$qbGameId = $em->createQueryBuilder(); $qbGameId->addSelect('distinct gameGameId.id'); $qbGameId->from('ZaysoCoreBundle:Event','gameGameId'); $qbGameId->leftJoin('gameGameId.teams','gameTeamGameId'); if ($date1) $qbGameId->andWhere($qbGameId->expr()->gte('gameGameId.date',$date1)); if ($date2) $qbGameId->andWhere($qbGameId->expr()->lte('gameGameId.date',$date2));
Now use dql for more information about the games themselves:
$qbGames = $em->createQueryBuilder(); $qbGames->addSelect('game'); $qbGames->addSelect('gameTeam'); $qbGames->addSelect('team'); $qbGames->addSelect('field'); $qbGames->addSelect('gamePerson'); $qbGames->addSelect('person'); $qbGames->from('ZaysoCoreBundle:Event','game'); $qbGames->leftJoin('game.teams', 'gameTeam'); $qbGames->leftJoin('game.persons', 'gamePerson'); $qbGames->leftJoin('game.field', 'field'); $qbGames->leftJoin('gameTeam.team', 'team'); $qbGames->leftJoin('gamePerson.person', 'person');
Kind of a long example, but I did not want to edit the material and may have broken it.
Cerad source share