Symfony1 使用Propel 1.4更新多行

Symfony1 使用Propel 1.4更新多行,symfony1,symfony-1.4,propel,Symfony1,Symfony 1.4,Propel,我需要执行以下查询(使用Propel 1.4/Symfony 1.4) 为此,我在symfony1.4中编写了以下代码 update notification set read=1 where to=6 AND action=0 $c=new Criteria() $c->add(NotificationPeer::TO, $memberId, Criteria::EQUAL); $c->add(NotificationPeer::ACTION, 0, Criteria::

我需要执行以下查询(使用Propel 1.4/Symfony 1.4)

为此,我在symfony1.4中编写了以下代码

update notification
set read=1
where to=6 AND
    action=0
$c=new Criteria()
$c->add(NotificationPeer::TO, $memberId, Criteria::EQUAL);
$c->add(NotificationPeer::ACTION, 0, Criteria::EQUAL);
$notification = NotificationPeer::doSelect($c);

foreach($notification as $notice)
{
    $notice->setRead(1);
    $notice->save();
}
它可以工作,但如果有100的通知给任何用户,它将花费100的查询和服务器不必要的负载。我看了一下推进的双重更新方法,我想它对我来说是可行的,但我不知道怎么做


有没有办法(我知道有,但我不知道)在一个查询中完成所有这些工作?

您应该建立两个标准:

  • where子句中的一个
  • 另一个用于update子句
//生成WHERE条件
$wherec=新标准();
$wherec->add(NotificationPeer::TO,$memberId,Criteria::EQUAL);
$wherec->add(NotificationPeer::ACTION,0,Criteria::EQUAL);
//生成更新的字段标准
$updc=新标准();
$updc->add(NotificationPeer::READ,1);
BasePeer::doUpdate($wherec、$updc、$con);

它执行一个(可能很大)查询。请参阅。

您应该建立两个标准:

  • where子句中的一个
  • 另一个用于update子句
//生成WHERE条件
$wherec=新标准();
$wherec->add(NotificationPeer::TO,$memberId,Criteria::EQUAL);
$wherec->add(NotificationPeer::ACTION,0,Criteria::EQUAL);
//生成更新的字段标准
$updc=新标准();
$updc->add(NotificationPeer::READ,1);
BasePeer::doUpdate($wherec、$updc、$con);
它执行一个(可能很大)查询。看