All get rolled back, that''s the whole point of a transaction. But
you''ll
need to use save! instead of save so that an exception is raised causing the
transaction to fail.
begin
Cool.transaction(cool, bad, sad) do
cool.name = "rufus"
cool.save!
bad.name = "ratty"
bad.save!
sad.name = "kinglsey"
sad.save!
end
rescue ActiveRecord::RecordInvalid => e
p e.record.errors.full_messages
end
-Jonathan
On 12/15/06, Matt Stone
<rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:>
>
> Hi,
>
> I''ve got a quick query on how rails database transactions work.
I''m a
> little confused by the chapter in the Agile book & the posts
I''ve
> searched on here.
>
> Say I have the following models
>
> cool
> bad
> sad
>
> & I update these in a transaction like so..
>
> Cool.transaction(cool, bad, sad) do
> cool.name = "rufus"
> cool.save
>
> bad.name = "ratty"
> bad.save
>
> sad.name = "kinglsey"
> sad.save
> end
>
> If the transaction fails.. do all db updates get rolled back, or just
> the Cool update?
>
> --
> 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
-~----------~----~----~----~------~----~------~--~---