【问题标题】:How to use Phalcon ORM for deleting a result set如何使用 Phalcon ORM 删除结果集
【发布时间】:2015-05-15 14:58:01
【问题描述】:

考虑以下代码表单文档

foreach (Robots::find("type='mechanical'") as $robot) {
    if ($robot->delete() == false) {
        echo "Sorry, we can't delete the robot right now: \n";
        foreach ($robot->getMessages() as $message) {
            echo $message, "\n";
        }
    } else {
        echo "The robot was deleted successfully!";
    }
}

使用 Phalcon,是否可以通过单个操作(无需迭代)删除结果集。

【问题讨论】:

    标签: php orm phalcon


    【解决方案1】:

    From \Phalcon\Mvc\Model\Resultset delete() 删除结果集中的每条记录。

    $robots = Robots::find("type='mechanical'");
    
    if($robots->delete()){
        echo "The robots were deleted successfully!";
    }
    

    【讨论】:

    • 我想知道用这种方式删除记录是否会运行SQL两次?一次用于 SELECT,另一次用于 DELETE
    • @LCB 如果查看源代码,您可以看到 Phalcon 创建了一个事务,然后在 resultset 中的每个对象上调用 delete,它仅在删除每条记录时才提交事务。
    猜你喜欢
    • 1970-01-01
    • 2013-10-11
    • 2013-06-18
    • 1970-01-01
    • 2012-06-03
    • 2014-10-15
    • 2017-03-09
    • 1970-01-01
    • 2011-09-25
    相关资源
    最近更新 更多