Ruby on Rails - multiple database connections in ruby on rails - ruby on rails tutorial - rails guides - rails tutorial - ruby rails
Multiple Database Connections in Ruby on Rails
A transaction acts on a single database connection. If you have multiple class-specific databases, the transaction will not protect interaction among them. One workaround is to begin a transaction on each class whose models you alter:
Student.transaction do
Course.transaction do
course.enroll(student)
student.units += course.units
end
end
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ruby on rails tutorial - rails guides - ruby rails - rubyonrails - learn ruby on rails - team
This is a poor solution, but fully distributed transactions are beyond the scope of ActiveRecord.