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 bar.save end foo.something += 1 foo.save #end transaction For even more complexity, what if a mail notification is sent for each bar modified in the collection? thanks, Jeff -- Posted via http://www.ruby-forum.com/.
Can you do:
Bar.transaction
foo.bars.each do |bar|
bar.something += 1
bar.save
end
end
-Jonny.
--
Posted via http://www.ruby-forum.com/.
I want the change to foo wrapped in the same transaction. I don''t think you can stick that in Bar.transaction? -Jeff -- Posted via http://www.ruby-forum.com/.
Yes, you can. -- -- Tom Mornini On Mar 8, 2006, at 9:06 AM, jeff cole wrote:> I want the change to foo wrapped in the same transaction. I don''t > think > you can stick that in Bar.transaction? > > -Jeff > > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Hi Tom,
How do you do it ? Jonny''s example seems vague... I need both model
to be save!
Thanks.
Tom Mornini wrote:> Yes, you can.
>
> --
> -- Tom Mornini
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---