-
-
Couldn't load subscription status.
- Fork 1.1k
Add "Nested Transactions" section #355
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -847,6 +847,28 @@ else | |
| end | ||
| ---- | ||
|
|
||
| === Nested Transactions [[nested-transactions]] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to what I said in the corresponding RuboCop PR, I think we could group this into a section about avoiding private APIs. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for your suggestion. However, there may be different reasons why private APIs should not be used, so I'm wondering if it's appropriate to group them all in one section. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the section should remain as it is because the focus should be more on the issues that arise with nested transactions rather than the use of private APIs. @wata727 I’ve been reading your blog, and I was wondering if you could elaborate a bit more on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm thinking about this PR again now, and I'm beginning to think that the section might not be suitable as a "style guide." I believe it’s worth having RuboCop find the problems caused by @koic Is there a chance we could add a cop without adding it to the style guide, or do you think problems like this are worth mentioning in the style guide? |
||
|
|
||
| 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]] | ||
|
|
||