[Proposal] Nested transactions
Since no one is interested in discussing this in the forums (http://forums.laravel.io/viewtopic.php?id=9610) I'll post it here.
Would it be possible to add a flag in the database Connection class that is set whenever transaction() is called, and if transaction() is called while this flag is set then the closure will be called without starting a second transaction in the database. This way I can safely nest transactions in PHP without needing to worry about which function requires a transaction.
To make it clearer:
DB::transaction(function() // this will call PDO::beginTransaction()
{
DB::transaction(function() // this won't call PDO::beginTransaction()
{
// but this closure will still be called
});
});
However, if this is a silly idea and there is a better way of doing this then I'm all ears.
Thanks
Just noticed @robclancy has already submitted the same issue
For who arrived here like me, searching about Laravel's nested DB transaction support: the issue mentioned above is https://github.com/laravel/framework/issues/1795, which is a duplicate of https://github.com/laravel/framework/issues/1686, and the important thing to know is that yes, it supports nested transactions - it has been implemented.
Thanks @jbruni
Yep, thanks for clarifying @jbruni
What version and above of Laravel is this in?
@vcardillo All releases since August 2nd 2013. (see https://github.com/laravel/framework/issues/1686#issuecomment-22013937)
Save points were added very recently too.
Hmm.then what about isolation level? Anyone here can tell how to specify a isolation level in laravel ? thank you.
@jbruni "it supports nested transactions - it has been implemented." really? how do I use it? any documentation? tried to search but found nothing =( thanks!
@punchi This doesn't need any docs. Just take a look at example in the beginning of the thread.
So glad this is fixed!
https://github.com/laravel/framework/commit/9957329279fced0a24ac3d9d02cfe99407fa8f54
ive just found this :)