使用连接的 Symfony2 和 Dooctrine Where 子句

Symfony2 & Dooctrine Where clause using a join

我有这样的查询;

$builder = $this->createQueryBuilder("p")
        ->where("p.published = :published AND p.mission.game_system = :game_system")
        ->orderBy("p.date_published", "DESC")
        ->setMaxResults($limit)
        ->setParameter("published", true)
        ->setParameter("game_system", $game_system);

p 是一个项目。

我只想获取特定游戏系统的项目,但游戏系统存储在任务中。我无法将游戏系统添加到项目中,因为这会创建递归引用。

如何启用 where 以仅获取特定游戏系统的项目?

例如,这将获取任务 ID 为 1 的所有项目;

$builder = $this->createQueryBuilder("p")
        ->where("p.published = :published AND p.mission = :mission")
        ->orderBy("p.date_published", "DESC")
        ->setMaxResults($limit)
        ->setParameter("published", true)
        ->setParameter("mission", 1);

但我想要所有与游戏系统相关的项目,这些项目存储在任务行中。任务和游戏系统是多对一关系

例如,我想要所有游戏系统 ID 为 5 的项目,无论任务如何,类似这样,但这失败了

$builder = $this->createQueryBuilder("p")
        ->where("p.published = :published AND p.mission.game_system = :game_system")
        ->orderBy("p.date_published", "DESC")
        ->setMaxResults($limit)
        ->setParameter("published", true)
        ->setParameter("game_system", 5);

这似乎可行,但这是正确的方法吗?

$builder = $this->createQueryBuilder("p")
    ->innerJoin('p.mission', 'm')
    ->innerJoin('m.game_system', 'gs')
    ->where("p.published = :published AND gs = :game_system")
    ->orderBy("p.date_published", "DESC")
    ->setMaxResults($limit)
    ->setParameter("published", true)
    ->setParameter("game_system", $game_system);