2014-06-06 57 views
0

我想執行還挺簡單的查詢,但我總能得到這個例外主義DQL - 字符串的預計結束時,得到了「內部」

[Syntax Error] line 0, col 157: Error: Expected end of string, got 'inner'

這裏是我的查詢:

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

你應該做你以前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(); 
} 
+0

@RafaelAdel爲什麼我回答你的問題?如果是這樣,你能否將我的答案標記爲已接受? – dmnptr