【问题标题】:Phalcon ORM Batch UpdatePhalcon ORM 批量更新
【发布时间】:2016-09-13 13:47:13
【问题描述】:

简单的问题,如果你们 Phalcon 用户.. 你知道我想要做什么。

$trueFind = ProductOrderTransaction::find(["conditions"=>"protPthdId = ".$id]);
$trueFind->setTransaction($transaction); 
$trueFind->protMomsId = $monitId;
$trueFind->protMomsName = $monitName;
if (!$trueFind->update()) {
    foreach ($trueFind->getMessages() as $message) {
        $this->flash->error($message);
        $transaction->rollback($message->getMessage());
    }
}

我只想在 orm Phalcon 中做这个查询:

UPDATE product_order_transaction set protMomsId = '$monitId' , protMomsName = '$monitName' WHERE protPthdId='$id'

失败 -> 回滚.. 成功 -> 提交。

【问题讨论】:

    标签: php phalcon phalcon-orm


    【解决方案1】:

    这样的?

    $items = ProductOrderTransaction::find([
        'conditions' => 'protPthdId = :id:',
        'bind' => ['id' => $id]
    ]);
    
    foreach($items as $item){
        $this->db->begin();
    
        $item->protMomsId = $monitId;
        $item->protMomsName = $monitName;
        $update = $item->update();
    
        if(!$update){
            $this->db->rollback();
            continue;
        }
        $this->db->commit();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-05
      • 1970-01-01
      • 2016-10-14
      • 1970-01-01
      • 1970-01-01
      • 2019-10-24
      • 2012-02-16
      • 1970-01-01
      相关资源
      最近更新 更多