我正在尝试执行有点简单的查询,但我总是得到这个异常
[语法错误]第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();
}
如何执行两个内连接?我的查询有问题吗?
答案 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();
}