我有这样的查询;
$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);
答案 0 :(得分:0)
这似乎有效,但这是正确的做法吗?
$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);