Farmer Schlutzenberg
2009-Jan-31 07:34 UTC
save after delete returns true but actually fails
Hi, I''m using Rails 2.2.2. I noticed that creating two references to the same database ActiveRecord object, then deleting with one of them, followed by saving with the other, true is returned, but no new record is actually saved. e.g.: doc=Document.new(:title => "sam''s speciality") doc.save doc.id # ==> 23 doc2=Document.find_by_title("sam''s speciality") doc2.delete doc.title # ==> "sam''s speciality" doc.save # ==> true doc3=Document.find_by_title("sam''s speciality") # ==> nil Should that second doc.save really return true? This situation could easily enough arise if two separate users are accessing the same record simultaneously. The same thing occurs when the model is using optimistic locking. It seems to me that in this case, it would be nice if the second doc.save raised an exception. (If one makes a change to one of doc''s fields immediately before the second save, then one does get an ActiveRecord::StaleObjectError exception.) - Farmer -- 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 -~----------~----~----~----~------~----~------~--~---