Forum: Ruby on Rails AR Transactions w/ multiple models - reality check ?

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.
peter.fitzgibbons (Guest)
on 2005-11-17 21:25
(Received via mailing list)
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,
Asa H. (Guest)
on 2005-11-17 23:05
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
Jonas B. (Guest)
on 2005-11-17 23:11
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
This topic is locked and can not be replied to.