Using SQL transactions with FUEL
Is it possible to use transactions when utilizing calls to separate models? I have a series of separate models for a online store that integrates with stripe and I want to make sure that all the insert calls to the models as well as the stripe call work before I commit everything. I searched the documentation but didn't see anything. I know it's possible via CodeIgniter but had no idea how that is impacted when in FUEL.
Comments
$db =& $CI->db; $my_model1->set_db($db); $my_model2->set_db($db); $my_model3->set_db($db); $db->trans_start(); $db->query('AN SQL QUERY...'); $db->query('ANOTHER QUERY...'); $db->query('AND YET ANOTHER QUERY...'); $db->trans_complete();
I haven't fully tested the transaction part yet but may be worth a shot to download the develop branch and try it out.
https://github.com/daylightstudio/FUEL-CMS/tree/develop
If you have written a model with transaction code for previous projects like I do and would like to leverage this code, simply add the model fuel/modules/models.
Then remove the part "extends CI_Model",
Add the connection through your __construct(){ $this->db = //connection details }
load the model in your controller as you normally would: $this->load->model(array('transac','other models'))
call your model when you need to do transactions :$this->transac->moveNode($id)