Using SQL transactions with FUEL

edited January 2015 in Feature Requests
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

  • edited 10:44PM
    Each model has a copy of the $CI->db object attached to it (to avoid conflicts with other model's active record). Because of this, you won't have the same db object across models. To hopefully help with this, in the develop branch I've extracted out the db initialization from within the model to a set_db method on a model so that you could potentially set your own common db object across models.
    $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
  • edited 10:44PM
    Hello,

    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)
Sign In or Register to comment.