doctrine-orm - Doctrine 2 更新不止一栏?

标签 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();

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

最佳答案

使用逗号分隔两个分配:

$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();

关于doctrine-orm - Doctrine 2 更新不止一栏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12153111/

相关文章:

php - 如何将新闻发送给带有特定标签的特定订阅者?

Symfony 表单设计

sql - 在另一个表 SQL Server 2008 中使用来自 SELECT 的 UPDATE 语句覆盖 ID 值

java - 在 Java 中使用 JProgressBar

php - 给定一个查询,我如何找到生成它的 ORM 方法?

php - 什么是用于从数据库获取用户的正确 security.yml 文件

如果值不为空,则更新数据库的 SQL 查询?

MYSQL移动平均计算优先级无限制

linux - 在 Linux 上更新 PyCharm

centos - centos 6.6中的yum更新错误