Forum: Ruby on Rails transaction question

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
jeff cole (Guest)
on 2006-03-08 01:19
How does one set up a transaction for multiple models?  For example, how
do you wrap the entire logic below in one transaction?

#begin transaction
for bar in foo.bars
  bar.something += 1

foo.something += 1
#end transaction

For even more complexity, what if a mail notification is sent for each
bar modified in the collection?

Jonathan V. (Guest)
on 2006-03-08 02:44
Can you do:

  foo.bars.each do |bar|
    bar.something += 1

jeff cole (Guest)
on 2006-03-08 19:06
I want the change to foo wrapped in the same transaction.  I don't think
you can stick that in Bar.transaction?

Tom M. (Guest)
on 2006-03-08 23:15
(Received via mailing list)
Yes,  you can.

-- Tom M.
leetc (Guest)
on 2007-04-19 10:59
Hi Tom,

    How do you do it ? Jonny's example seems vague... I need both model
to be save!


Tom M. wrote:
> Yes,  you can.
> --
> -- Tom M.
This topic is locked and can not be replied to.