framework icon indicating copy to clipboard operation
framework copied to clipboard

[Proposal] Nested transactions

Open meowcakes opened this issue 13 years ago • 12 comments

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

meowcakes avatar Jul 05 '13 22:07 meowcakes

Just noticed @robclancy has already submitted the same issue

meowcakes avatar Jul 05 '13 23:07 meowcakes

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.

jbruni avatar Apr 01 '14 01:04 jbruni

Thanks @jbruni

goyote avatar Jun 18 '14 19:06 goyote

Yep, thanks for clarifying @jbruni

bkuhl avatar Sep 04 '14 14:09 bkuhl

What version and above of Laravel is this in?

vcardillo avatar Oct 12 '15 21:10 vcardillo

@vcardillo All releases since August 2nd 2013. (see https://github.com/laravel/framework/issues/1686#issuecomment-22013937)

jbruni avatar Oct 17 '15 21:10 jbruni

Save points were added very recently too.

GrahamCampbell avatar Oct 17 '15 21:10 GrahamCampbell

Hmm.then what about isolation level? Anyone here can tell how to specify a isolation level in laravel ? thank you.

nakupanda avatar Oct 28 '15 02:10 nakupanda

@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 avatar Nov 27 '15 17:11 punchi

@punchi This doesn't need any docs. Just take a look at example in the beginning of the thread.

rkgrep avatar Nov 28 '15 04:11 rkgrep

So glad this is fixed!

filipbekic01 avatar Jan 26 '17 15:01 filipbekic01

https://github.com/laravel/framework/commit/9957329279fced0a24ac3d9d02cfe99407fa8f54

ive just found this :)

lloricode avatar Jan 10 '18 03:01 lloricode