CodeIgniter Forums
Transactions between models - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Transactions between models (/showthread.php?tid=49549)



Transactions between models - El Forum - 02-24-2012

[eluser]Unknown[/eluser]
I'm starting to implement the Transactions Library, and would like to know if transactions can be 'transferred' between models. I know this works:
Code:
$this->db->trans_start();
$this->db->query('AN SQL QUERY...');
$this->db->query('ANOTHER QUERY...');
$this->db->query('AND YET ANOTHER QUERY...');
$this->db->trans_complete();

But would this work if I call trans_start() and trans_stop() in a controller, and then the actual queries run inside models?
Code:
$this->db->trans_start();
$this->model1->random_db_insert_function_A('data');
$this->model2->random_db_insert_function_B('data');
$this->db->trans_complete();

If not, could I somehow tag each of the database queries as part of a set that is defined in the controller? Thanks for your thoughts.


Transactions between models - El Forum - 02-24-2012

[eluser]Mauricio de Abreu Antunes[/eluser]
Controll your transactions in your controllers.
Transcations are independents of models.


Transactions between models - El Forum - 02-27-2012

[eluser]Aken[/eluser]
Create a test area and try it.