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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Michael Koziarski
2009-Feb-02 02:59 UTC
Re: save after delete returns true but actually fails
> 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.)Does this still happen if you turn off partial updates for the class? Document.partial_updates = false # that stuff I think it''s just the partial updates code detecting you haven''t saved anything and ''optimising'' the call to save. -- Cheers Koz --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---