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 -- Posted via http://www.ruby-forum.com/.
Nick Stuart
2006-Mar-30 15:55 UTC
[Rails] Transactions with different types of model object
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 On 3/30/06, Chris <evilgeenius@gmail.com> wrote:> 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 > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >