Created
June 24, 2014 11:57
-
-
Save gilr00y/bb15ef30be9a6656d4ef to your computer and use it in GitHub Desktop.
ActiveRecord Cross-DB transactions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# AR transactions wrap a block of code, issuing a rollback if any errors are raised, | |
# returning result of block if no errors. | |
#(note: this gist makes use of SecondBase https://github.com/customink/secondbase) | |
AR = ActiveRecord::Base | |
AR.transaction { 14 } #=> 14 | |
# Errors are propagated... | |
AR.transaction { raise } #=> RuntimeError | |
# ...except ActiveRecord::Rollback errors | |
AR.transaction { raise ActiveRecord::Rollback } #=> nil | |
# -- | |
# What does this mean cross-db?? | |
# -- | |
# We can nest transactions! | |
AR.transaction { | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment