From 91a682c372ffb1c3e61d13e25b51455fb2decc68 Mon Sep 17 00:00:00 2001 From: Kazuma Watanabe Date: Sun, 11 Feb 2024 16:43:15 +0900 Subject: [PATCH] Add "Nested Transactions" section --- README.adoc | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/README.adoc b/README.adoc index 47652a5..f0971af 100644 --- a/README.adoc +++ b/README.adoc @@ -847,6 +847,28 @@ else end ---- +=== Nested Transactions [[nested-transactions]] + +Use `requires_new: true` if you want to avoid nested transactions unintentionally becoming part of the parent transaction. +`joinable: false` is a private API and should not be used. If used, serious side effects may occur, such as `after_commit` not working properly. + +[source,ruby] +---- +# bad +ActiveRecord::Base.transaction(requires_new: true, joinable: false) do + ActiveRecord::Base.transaction do + # ... + end +end + +# good +ActiveRecord::Base.transaction(requires_new: true) do + ActiveRecord::Base.transaction(requires_new: true) do + # ... + end +end +---- + == Models: Active Record Queries [[activerecord-queries]] === Avoid Interpolation [[avoid-interpolation]]