Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
ORM subsequent delete, save model actions participating in same transaction
  • Is it possible to have delete and save model actions participating in same transaction?

    I have a situation when I need to delete some rows of a has_many related model

    unset($order->order_detail[$k]);   
    $value->delete(null, true);

    later on have a

    $order->save(null, true);

    will those 2 participate or not in same transaction, how do I make them participate in same transaction?


  • HarroHarro
    Accepted Answer
    If you unset a related child object, and you subsequently save the parent, those related objects will be unlinked from the relation, but not deleted.

    If you want to delete them, you need to delete them seperately.

    If you want multiple ORM actions in a single database transaction, you can use

    DB::start_transation() / DB::commit_transaction() / DB::rollback_transaction()

    to wrap them into a single transaction. Obviously, you need to capture errors from the ORM actions manually to do a proper rollback if needed.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion