I am trying to wrap the updating of two models in a transaction and when the transaction fails it is not rolling back. My method is : def update_attributes(user,params) @user = user @company = user.company begin User.transaction do @user.update_attributes!(params[:user]) @company.update_attributes!(params[:company]) end true rescue false end end In the above method , if @user fails @company will not be saved but not vice versa. My question is am I using transactions correctly and if so what am I doing wrong? thanks James --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Aug-26 20:30 UTC
Re: transaction not working with update_attributes!
On Aug 26, 6:26 pm, jjburka <jjbu...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I am trying to wrap the updating of two models in a transaction and > when the transaction fails it is not rolling back. >Does activerecord try to do a rollback (check the logs) ? Are you using a database that supports transaction (ie not mysql with myisam tables)? Fred> My method is : > > def update_attributes(user,params) > @user = user > @company = user.company > begin > User.transaction do > @user.update_attributes!(params[:user]) > @company.update_attributes!(params[:company]) > end > true > rescue > false > end > > end > > In the above method , if @user fails @company will not be saved but > not vice versa. My question is am I using transactions correctly and > if so what am I doing wrong? > > thanks > James--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---