Add transaction_with for transaction multiple models related #2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This feature supports transaction using multi models.
Using multi models in a transaction...
It is not "DRY".
In this case, Book1 and Book2 has a same db connection.
Therefore, we do not need that write twice a "with_writable".
When we write code like this, we must think that switch "readable, writable".
And, transaction must need a same connection.
Now, using this patch...
It is "DRY" and easier to understand the intention.
Also, user does not run of unintended query to DB.
(ex. User did not know Book2 using other DB.)
It will raise a exception in that case.
But, this method is declarative.
You can switch a connection in a block of transaction_with.