Different ActiveRecord classes in a single transaction

suggest change

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:

Account.transaction do
  balance.save!
  account.save!
end

The transaction method is also available as a model instance method. For example, you can also do this:

balance.transaction do
  balance.save!
  account.save!
end

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


ActiveRecord transactions:
*Different ActiveRecord classes in a single transaction

Table Of Contents
39ActiveRecord transactions
55CSV