Multiple database connections
suggest changeA 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
This is a poor solution, but fully distributed transactions are beyond Active Record. Nested transaction blocks only help when Student and Course use different connections. On one connection, the inner block joins the outer transaction.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents