如何将同一元组上的这两个更新合并为一个操作?
$q = $this->em->createQuery('update EntityUserEn 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 EntityUserEn u set u.contribution = :contribution where u.name = :name');
$q->setParameters( array(
'contribution' => $this->rContributionUser($theUser),
'name' => $theUser,
));
$q->getResult();
我认为一次更新比两次更新便宜。
使用逗号分隔两个赋值:
$q = $this->em->createQuery('update EntityUserEn 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();