Ruby on Rails - different activerecord classes in a single transaction in ruby on rails- ruby on rails tutorial - rails guides - rails tutorial - ruby rails
Different ActiveRecord classes in a single transaction
Though the transaction class method is called on some ActiveRecord class, the objects within the transaction block need not all be instances of that class. This is because transactions are per-database connection, not per-model. In this example a balance record is transactionally saved even though transaction is called on the Account class:
The transaction method is also available as a model instance method. For example, you can also do this: