Peter Fitzgibbons
2005-Nov-17 19:23 UTC
AR Transactions w/ multiple models - reality check ?
Hello, As Dave demonstrates in AWDR, p242 "Transactions", User.transaction(user) do Account.transaction(account) do account.save #success user.save #failure end end Unlike his example, my User and Account are actually on teh same database... in my example, does the failure of user.save reverse the transaction? Thanks, -- Peter Fitzgibbons _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Asa Hopkins
2005-Nov-17 21:05 UTC
Re: AR Transactions w/ multiple models - reality check ?
Something like that. I know I switched to .save! (it throws an exception when it fails, instead of just returning "false"), and it may be that I had to do that to get nested transactions like this to work right. (Right being defined as that neither table is changed if either one fails.) Hope that helps, Asa peter.fitzgibbons wrote:> Hello, > > As Dave demonstrates in AWDR, p242 "Transactions", > User.transaction(user) do > Account.transaction(account) do > account.save #success > user.save #failure > end > end > > Unlike his example, my User and Account are actually on teh same > database... > in my example, does the failure of user.save reverse the transaction? > > Thanks,-- Posted via http://www.ruby-forum.com/.
Jonas Bengtsson
2005-Nov-17 21:11 UTC
Re: AR Transactions w/ multiple models - reality check ?
Do you mean "save!"? "save" doesn''t result in an exception as far as I know but "save!" does. If you have just one database, do you really need User.transaction and Account.transaction? Wouldn''t it suffice with just one? (I know just about nothing about Rails'' transaction support) /Jonas peter.fitzgibbons wrote:> Hello, > > As Dave demonstrates in AWDR, p242 "Transactions", > User.transaction(user) do > Account.transaction(account) do > account.save #success > user.save #failure > end > end > > Unlike his example, my User and Account are actually on teh same > database... > in my example, does the failure of user.save reverse the transaction? > > Thanks,-- Posted via http://www.ruby-forum.com/.