I run transaction from method in class A, inside the transaction, I call method from class B and C in order. The method in class B and C also have transactions. So here's my question:
Why after the method in class B finish transaction, it commits to database and not wait until method in class C finish first? They're in scope of class A method's transaction. Is it supposed to happen this way? I thought it'll wait for all nested transaction in class A method for finish before commit the whole data.
#Nested Transaction
3 messages · Page 1 of 1 (latest)
I don't think transactions are supposed to be nested. It should all be 1 transaction
Even though some databases (e.g. MySQL) don't support nested transactions, I believe Laravel performs some magic behind the scenes that should make it work. For instance feature tests using the RefreshDatabase trait will run the test inside a transaction, and it works even if the tested code also uses transactions.
However there are some DB statements that can't run in a transaction, like altering or truncating tables. If you do that inside a transaction, it will trigger an implicit commit, which in effect breaks the transaction. At least that is the case with MySQL - I'm not sure how other DBMS work.
Please show a simplified example of how your transactions are performed.