![]() |
Hi, everyone knows how to use transaction, right?
Code: <?php But the truth is will be more useful to use transaction with the model. Something Like This: Code: $UserModel->db->transStart(); But this approach seems not work. Anyone advice?
Please read this and you may need to use the if/else structure to test the transaction.
CodeIgniter 4 User Guide - Working with Databases - Transactions - Running Transactions Manually What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
....Meh
Try to make the question in a different way: can you please post an example of transactions using Model object ? thanks
Your sample code should work.
What's wrong exactly? (11-23-2022, 10:40 PM)kenjis Wrote: Your sample code should work. Transaction will not consider validation rules failure as a fail query so if we put a data that didn't mach validationRules it will not perform query but neither trow an error on transaction and the transaction will be committed. Maybe i should open a ticket on ci4 github about that?
Transaction has nothing to do with validation in model. So your code does not work correctly.
I think Model should throw an exception if a validation error occurs. > Maybe i should open a ticket on ci4 github about that? Yes.
But the current behavior does not seem a bug.
Quote:Now, whenever you call the insert(), update(), or save() methods, the data will be validated. If it fails, the model will return boolean false. You can use the errors() method to retrieve the validation errors: According to the documentation, developers need to check if there are validation errors.
I found a solution. The code below:
Code: $UserModel->db->transStart(); Turn into: Code: $this->db->transBegin(); That's all. Enjoy (11-27-2022, 01:37 AM)RedWd Wrote: I found a solution. The code below: $this->db, $userModel and $profilModel are using a same connection? |
Welcome Guest, Not a member yet? Register Sign In |