Forum: Ruby on Rails Transactions with different types of model object

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Chris (Guest)
on 2006-03-30 19:20
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
Nick S. (Guest)
on 2006-03-30 19:57
(Received via mailing list)
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
Chris (Guest)
on 2006-03-30 20:20
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
This topic is locked and can not be replied to.