Is it possible to have one “transaction” with to separate models.
I want to insert a post with their tags. Tags and Posts are in two separate models.
How can i achive to handle it with a transaction? (Like below:)
$this->db->trans_start();
$this->post_model->insert('...');
$this->tags_model->insert('...');
$this->db->trans_complete();
As long as you don’t have other transaction statements in your model methods, your sample code should work fine.
As per the documentation, you can test it by passing
TRUEto$this->db->trans_start():Passing
TRUEtotrans_start()will automatically rollback the transaction upon completion. You should be able to check auto_increment values on your tables (if applicable) to see if the transaction worked or not.