Doctrine 2 如何一次增加多行的列?

Doctrine 2 how to increment a column for multiple rows at once?

我正在寻找一种在不循环的情况下一次增加多行值的方法,这在学说中可行吗? 这是简单的查询 sql :

$sql = "UPDATE table set compteur = compteur + 1 where id in ('1','2','3') ";

使用原则更新多行(不递增),我有这个:

$qb = $this->getEntityManager()->createQueryBuilder();
                    $query = $qb->update('Application\Entity\Table', 'l')
                            ->set('l.compteur', $qb->expr()->literal('8'))
                            ->where("l.id in ('$ids')")
                            ->getQuery();
                    $retour = $query->execute();

感谢任何想法!!

为此使用 DQL:

$this->getEntityManager()->createQuery('
    UPDATE Application\Entity\Table t
    SET t.compteur = t.compteur + 1
')
->execute();

http://doctrine-orm.readthedocs.org/projects/doctrine-orm/en/latest/reference/batch-processing.html#dql-update

您也可以像这样使用查询生成器:

$qb->set('l.compteur', $qb->expr()->sum('l.compteur', 1));