【问题标题】:Joining 2 results in Doctrine throws error加入 2 导致 Doctrine 抛出错误
【发布时间】:2016-09-17 14:28:20
【问题描述】:

我正在尝试在 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();

【问题讨论】:

    标签: doctrine-orm dql doctrine-query


    【解决方案1】:

    你混合了 Doctrine2 的 2 个概念:

    • 使用 SQL
    • 使用 DQL

    如果你想实现你想要的,构建表选择,而不是实体选择,你应该使用EntityManager::createNativeQuery() 方法并将 SQL 查询设置为参数。

    EntityManager::createQuery() 仅用于 DQL 查询

    【讨论】:

      猜你喜欢
      • 2021-05-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-03
      • 2010-09-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多