Hi, I have a transaction in which a duplicate key exception is being thrown by MySQL. I assume this happens when I try to do a save. The problem is that before the save, I do a destroy on another object as part of the transaction. Catching the exception by doing this, User.transaction do begin objA.destroy objB.save <-- causing exception rescue Exception => exc flash[:notice] = .... end end does not rollback the destroy. Any help would be appreciated. Thanks, Sam -- 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 -~----------~----~----~----~------~----~------~--~---
Could this be because of using MyISAM tables rather than InnoDB? Thanks. On 10/2/06, Sam Donaldson <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > Hi, > > I have a transaction in which a duplicate key exception is being thrown > by MySQL. I assume this happens when I try to do a save. The problem > is that before the save, I do a destroy on another object as part of the > transaction. Catching the exception by doing this, > > User.transaction do > begin > objA.destroy > objB.save <-- causing exception > rescue Exception => exc > flash[:notice] = .... > end > end > > does not rollback the destroy. Any help would be appreciated. > > Thanks, > > Sam > > -- > 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 -~----------~----~----~----~------~----~------~--~---
On 10/2/06, Sam Donaldson <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > I have a transaction in which a duplicate key exception is being thrown > by MySQL. I assume this happens when I try to do a save. The problem > is that before the save, I do a destroy on another object as part of the > transaction. Catching the exception by doing this,Rescue the exception *outside* of the transaction block. Be sure to use a database that supports transactions (not MySQL + MyISAM.) begin User.transaction do objA.destroy objB.save! end rescue Exception => exc flash[:notice] = ... end 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 -~----------~----~----~----~------~----~------~--~---