How to delete many records in Phalcon


Feb '15

Jun '17

2

2541

1


Thien
31.3k

I just share tip delete :)

When you want delete record in table, for example we have a table is PostsTags. You can also delete many records by traversing a resultset with a foreach or not use foreach

Phase1

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

Phase2

    PostsTags::find('postsId =' . $object->getId())->delete();

Here value "$object" is object of table PostsTags, done


止戈
70

what doest the object means here ? Is it a Model object from like PostsTags::findFirst() ?


止戈
70

Does the batch update method like delete? like this: "update cars set status=0 where status=1 and update_time <= 1498101758" ?