在我的 Symfony 3.2 项目中,我想展示在and by = 1themes
中使用的所有内容。table1
table2
user_id
这是在 PhpMyAdmin 中完美运行的 MySQL 查询:
SELECT DISTINCT themes.*
FROM themes
WHERE EXISTS
(SELECT *
FROM table1
WHERE table1.theme_id = themes.id
AND table1.user_id = 1)
OR EXISTS
(SELECT *
FROM table2
WHERE table2.theme_id = themes.id
AND table2.user_id = 1)
ORDER BY themes.name;
问题是我无法ThemeRepository
在我的项目中为我的班级翻译它......我尝试了这段代码:
public function findAllUsedByUserId($userId) {
return $this->getEntityManager()
->createQuery('
SELECT DISTINCT t
FROM AppBundle:Theme t
WHERE EXISTS
(SELECT *
FROM AppBundle:Table1 a
WHERE a.theme_id = t.id
AND a.user_id = :userId)
OR EXISTS
(SELECT *
FROM AppBundle:Table2 b
WHERE b.theme_id = t.id
AND b.user_id = :userId)
ORDER BY t.name ASC
')
->setParameter('userId', $userId)
->getResult();
}
输出是一个错误:[Syntax Error] line 0, col 131: Error: Unexpected '*'
有人可以帮我查询吗?提前致谢!