Create transaction using delete method... failed

152 Views Asked by At

I want to create transaction query with this code :

    // Start a transaction
    ORM::get_db()->beginTransaction();

    //this work
    $prs = Model::factory('PenyediaJasaORM')->find_one(77);
    $prs->delete();

    //yes this not work, i know 
    $klas = Model::factory('PenyediaJasaKlasifikasiORM')->find_one(100);
    $klas->delete();


    // Commit a transaction
    ORM::get_db()->commit();

yes on $prs query it works. i made the $klas not work to see the outcome. but why i got error 'Fatal error: Call to a member function delete() on boolean in'.

i think the appropriate error would be FALSE not FATAL ERROR since those query is transaction.

please give suggestion to me if i am not fully understood transaction using multiple delete query.

thanks

1

There are 1 best solutions below

2
Eduardo Pacios On

Your query:

Model::factory('PenyediaJasaKlasifikasiORM')->find_one(100);

returns false if doesn't find anything. You should check if your $klas variable is not false, call $klas->delete()

if($klas) {
    $klas->delete();
}