In case of a single transation we can apply transation on one database. What if we need transactions on multiple databases? Rails supports nested transactions for this but before using it ,read about it carefully.
Suppose we have two databases A and B. You want to apply transactions on both the databases so that either two of these databases get updated together or nothing gets updated.
If you rollback the transaction this way, only the operations of database B are rolled back in this case becuase you are rollbacking the transactions of inner block.Other options are executed too.
If you rollback the transaction this way, only the operations of database A are rolled back because transaction block for B has alreday ended.
In this case operations related to A are rolled back and system does not execute B’s transaction block.
Case 4(A valid way):
In this case both the transactions are rollbacked.
If you want to rollback both the transactions using ActiveRecord::Rollback you have to use raise ActiveRecord::Rollback in both inner and outer block.
Check out this blog post,you will find it helpful.comments powered by Disqus