Doctrine DQL - 字符串的预期结束,内部'

时间:2014-06-06 22:15:02

标签: mysql symfony join doctrine-orm dql

我正在尝试执行有点简单的查询,但我总是得到这个异常

  

[语法错误]第0行,第157行:错误:字符串的预期结束,得到   '内'

这是我的疑问:

public function hasRecord($user, $event)
{
    $q = $this->getEntityManager()->createQuery("
                select count(h.id) from Tsk\FEBundle\Entity\History h
                inner join h.user u where u.id = :user
                inner join h.event v and v.id = :event
            ");

    $q->setParameters([
        "user" => $user,
        "event" => $event
    ]);
    return $q->getSingleScalarResult();
}

如何执行两个内连接?我的查询有问题吗?

1 个答案:

答案 0 :(得分:1)

您应该在where子句之前进行联接:

public function hasRecord($user, $event)
{
    $q = $this->getEntityManager()->createQuery("
                select count(h.id) from Tsk\FEBundle\Entity\History h
                inner join h.user u
                inner join h.event v
                where u.id = :user
                and v.id = :event
            ");

    $q->setParameters([
        "user" => $user,
        "event" => $event
    ]);
    return $q->getSingleScalarResult();
}