我正在尝试在DQL
中加入2个查询,但我收到的错误是,
[Semantical Error] line 0, col 114 near '(select u.email': Error: Class '(' is not defined.
我经历过 https://stackoverflow.com/questions/24600439/error-in-nested-subquery-in-dql-class-is-not-defined。但我无法弄明白。请帮忙。
我的查询如下:
$filterQuery = "SELECT tempResult1.email as email,tempResult1.name as name , tempResult1.id as user
FROM (select u.email as email,a.name as name , u.id as user
FROM
Application\Entity\Userhasrole uhr
INNER JOIN
Application\Entity\Oauthrole r with uhr.applicationrole = r.id
INNER JOIN
Application\Entity\Application a with r.application = a.id
INNER JOIN
Application\Entity\Oauthusers u
) tempResult1
LEFT JOIN
(SELECT uhr1.user as user FROM Application\Entity\Userhasrole uhr1 where
a.id = :applicationId
) tempResult2
with tempResult1.user = tempResult2.user";
$queryObject = $this->getEntityManager()
->createQuery($filterQuery);
$queryObject->setParameter('applicationId', $applicationId);
$result = $queryObject->getResult();
答案 0 :(得分:0)
你混合了Doctrine2的两个概念:
如果要实现所需,建立表选择而不是实体选择,则应使用EntityManager::createNativeQuery()
方法并将SQL查询设置为参数。
EntityManager::createQuery()
仅用于DQL查询