0

我在 ZF2 代码中使用 Doctrine 2,我正在尝试编写更新查询。代码是这样的:

    $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 抱怨查询。确切的错误消息是:(string) [Syntax Error] line 0, col 87: Error: Expected Literal, got 'group'

4

1 回答 1

1

关键字组似乎产生了问题。当我使用 gr alias 而不是 group 时,它工作正常。所以,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);
于 2013-06-20T15:02:35.880 回答