CodeIgniter Forums
Are Transactions supported together with the usage of Models? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Are Transactions supported together with the usage of Models? (/showthread.php?tid=72496)



Are Transactions supported together with the usage of Models? - HardyW - 12-30-2018

I would like to combine several model save operations within one transaction unit. I only know that
  1. transactions are supported as methods of the connection interface
  2. the model class does not provide access to the used connection interface
Therefore, I do not see a possibility to combine this functionality. Am I missing anything? Is there any other possibility to use transactions together with models?


RE: Are Transactions supported together with the usage of Models? - kilishan - 12-30-2018

That's a good question, actually. The _call method and the builder instance should allow you to access the transactions through the model but I honestly haven't tried it.


RE: Are Transactions supported together with the usage of Models? - HardyW - 12-31-2018

(12-30-2018, 08:34 PM)kilishan Wrote: That's a good question, actually. The _call method and the builder instance should allow you to access the transactions through the model but I honestly haven't tried it.

Thanks! It works via the __call method. Did not know about it. Perhaps it is worthwhile to mention anywhere at a prominent place that methods of the builder and the database connection can be used directly from the model.

PS: It is actually indirectly mentioned at a hidden place: in the note paragraph of the "Working With Query Builder" section.


RE: Are Transactions supported together with the usage of Models? - kilishan - 12-31-2018

Glad to hear it works! And you're right that could be a bit clearer. Once we hit beta I'm sure there will be a big focus on more docs cleanup.