AR Transactions w/ multiple models - reality check?



As Dave demonstrates in AWDR, p242 “Transactions”,
User.transaction(user) do
Account.transaction(account) do #success #failure

Unlike his example, my User and Account are actually on teh same
in my example, does the failure of reverse the transaction?



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,


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)