如何将同一元组的这两个更新合并为一个操作?
$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次更新便宜。
答案 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();