On 10/6/06, Ianne Leson
<rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:>
> I have a transaction block as follow:
>
> begin
> Hello.transaction(input1,input2)
>
> input1.save
>
> for i in 0 to count
> input2[i].input1_id = input1.id
> input2[i].save
> end
> end
> rescue
>
> end
>
> I have used validates_uniqueness_of for input2 in the model
>
> The problem is, when there is duplicate record in input2, input1 and the
> first record in input2 are inserted into db and commited.
You need to raise an exception so the transaction knows to rollback, so use
save! (raises ActiveRecord::RecordInvalid when invalid) instead of save
(returns false when invalid).
jeremy
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---