如何使用 Phalcon ORM 删除结果集

How to use Phalcon ORM for deleting a result set

考虑以下代码形式的文档

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,是否可以通过一次操作(无需迭代)删除结果集。

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

$robots = Robots::find("type='mechanical'");

if($robots->delete()){
    echo "The robots were deleted successfully!";
}