Transactions with different types of model object


#1

If i have three types of model objects, say an account, a person and a
tree :

account=Account.find(…
person=Person.find(…
tree=Tree.find(…

How do i start a transaction over the three of them. As far as i am
aware doing it like this only covers the account objects :

Account.transaction do
account.withdraw(20)
person.add_money(200)
tree.remove_leaves(23)
end

Any ideas??

Thanks,
Chris


#2

Well the above will do what you want. All the Account.transaction does
is start a BEGIN … COMMIT sequence for you. There is no table level
transactions per-se.

Take a look at the logs when you run the above code, and watch the SQL
code. You’ll see it in there.

-Nick


#3

Thanks Nick,

my problem was that by default rails doesn’t revert the objects to their
original state.

How do you manually abort a transaction?

Thanks