2013-06-20 76 views
0

我在ZF2代碼中使用Doctrine 2,我試圖編寫更新查詢。 代碼是這樣的:doctrine2查詢生成器有什麼問題 - 預期的文字

$qb = $this->getEntityManager()->createQueryBuilder(); 
    $qb->update('Application\Entity\Groups', 'group') 
      ->set('group.state', '?1') 
      ->set('group.modified', '?2') 
      ->where($qb->expr()->eq('group.id', '?3')) 
      ->setParameter(1, \Application\Entity\Groups::STATE_DELETED) 
      ->setParameter(2, $modified) 
      ->setParameter(3, $group_id); 

Doctrine2抱怨查詢。確切的錯誤信息是: (字符串)[語法錯誤]行0,列87:錯誤:預計字面值,得到'組'

回答

1

似乎關鍵字組創建問題。當我使用GR別名而不是組時,它工作正常。所以,DQL波紋管工作:

$qb = $this->getEntityManager()->createQueryBuilder(); 
    $qb->update('Application\Entity\Groups', 'gr') 
      ->set('gr.state', ':state') 
      ->set('gr.modified', ':modified') 
      ->where($qb->expr()->eq('gr.id', ':group_id')) 
      ->setParameter('group_id', $group_id) 
      ->setParameter('state', \Application\Entity\Groups::STATE_DELETED) 
      ->setParameter('modified', $modified);