Doctrine 2更新了多个列?

时间:2012-08-28 05:09:36

标签: doctrine-orm sql-update updates

如何将同一元组的这两个更新合并为一个操作?

$q = $this->em->createQuery('update \Entity\UserEn u set u.last = :last where u.name = :name');
$q->setParameters( array(
    'last'  => new \DateTime($newLast),
    'name'  => $theUser,

));
$q->getResult();


$q = $this->em->createQuery('update \Entity\UserEn u set u.contribution = :contribution where u.name = :name');
$q->setParameters( array(
    'contribution'  => $this->rContributionUser($theUser),
    'name'          => $theUser,

));
$q->getResult();

我认为一次更新比2次更新便宜。

1 个答案:

答案 0 :(得分:2)

使用逗号分隔两个作业:

$q = $this->em->createQuery('update \Entity\UserEn u set u.last = :last, u.contribution = :contribution where u.name = :name');
$q->setParameters( array(
    'last'         => new \DateTime($newLast),
    'contribution' => $this->rContributionUser($theUser),
    'name'         => $theUser,
));
$q->getResult();