Adam Greene
2008-Oct-02 21:37 UTC
partial_updates does not work when calling save_without_validation!
hey folks, I migrated to 2.1 from 2.0.2, turned on the partial_update functionality, and specs started to fail. It seems that calling ''save_without_validation!'' on an existing object does not trigger the save_with_dirty! method. The path is a bit convoluted, but when save_without_validation! is called... it calls: ActiveRecord::Base#update method -> then is overloaded by ActiveRecord::Dirty#update_with_dirty, which does not clear out the changed attributes. adding a patch like the one pasted at the bottom of this msg fixes the issue. I''m not sure if this is the right fix or not. It seems that calling save_without_validation! should still call the save_with_dirty! method, just like save! calls the save_with_dirty! method. The fact that it calls the update_with_dirty might just be ''luck''? Thanks, Adam **PATCH** # HACK: why does this not work if I chain it from within the module Dirty? # It doesn''t seem to pick it up if I use update_with_dirty_with_patch # and *_without_patch.... but this works as it is patched in after # ActiveRecord::Base has been extended with ActiveRecord::Dirty module ActiveRecord class Base def update_with_patch update_without_patch #FIX: make sure the changed attributes are cleared out after a successful update!!! changed_attributes.clear rescue nil end alias_method_chain :update, :patch end end --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Adam Greene
2008-Oct-02 21:39 UTC
Re: partial_updates does not work when calling save_without_validation! [PATCH included]
just noting that I threw a possible patch down at the bottom of the note.... On Oct 2, 2:37 pm, Adam Greene <adam.gre...@gmail.com> wrote:> hey folks, > I migrated to 2.1 from 2.0.2, turned on the partial_update > functionality, and specs started to fail. It seems that calling > ''save_without_validation!'' on an existing object does not trigger the > save_with_dirty! method. > > The path is a bit convoluted, but when save_without_validation! is > called... it calls: > ActiveRecord::Base#update method -> then is overloaded by > ActiveRecord::Dirty#update_with_dirty, which does not clear out the > changed attributes. > > adding a patch like the one pasted at the bottom of this msg fixes the > issue. > > I''m not sure if this is the right fix or not. It seems that calling > save_without_validation! should still call the save_with_dirty! > method, just like save! calls the save_with_dirty! method. The fact > that it calls the update_with_dirty might just be ''luck''? > > Thanks, > Adam > > **PATCH** > > # HACK: why does this not work if I chain it from within the module > Dirty? > # It doesn''t seem to pick it up if I use update_with_dirty_with_patch > # and *_without_patch.... but this works as it is patched in after > # ActiveRecord::Base has been extended with ActiveRecord::Dirty > module ActiveRecord > class Base > def update_with_patch > update_without_patch > #FIX: make sure the changed attributes are cleared out after a > successful update!!! > changed_attributes.clear rescue nil > end > alias_method_chain :update, :patch > > end > end--~--~---------~--~----~------------~-------~--~----~ 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
2008-Oct-03 20:15 UTC
Re: partial_updates does not work when calling save_without_validation!
> hey folks, > I migrated to 2.1 from 2.0.2, turned on the partial_update > functionality, and specs started to fail. It seems that calling > ''save_without_validation!'' on an existing object does not trigger the > save_with_dirty! method.Why are you calling save_without_validation!? If you want to save without validations the ''public'' api is: @object.save(false) The bang seems counter-intuitive?> The path is a bit convoluted, but when save_without_validation! is > called... it calls: > ActiveRecord::Base#update method -> then is overloaded by > ActiveRecord::Dirty#update_with_dirty, which does not clear out the > changed attributes. > > adding a patch like the one pasted at the bottom of this msg fixes the > issue. > > > I''m not sure if this is the right fix or not. It seems that calling > save_without_validation! should still call the save_with_dirty! > method, just like save! calls the save_with_dirty! method. The fact > that it calls the update_with_dirty might just be ''luck''? > > > Thanks, > Adam > > > **PATCH** > > # HACK: why does this not work if I chain it from within the module > Dirty? > # It doesn''t seem to pick it up if I use update_with_dirty_with_patch > # and *_without_patch.... but this works as it is patched in after > # ActiveRecord::Base has been extended with ActiveRecord::Dirty > module ActiveRecord > class Base > def update_with_patch > update_without_patch > #FIX: make sure the changed attributes are cleared out after a > successful update!!! > changed_attributes.clear rescue nil > end > alias_method_chain :update, :patch > > end > end > > > > > > >-- 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 -~----------~----~----~----~------~----~------~--~---
Adam Greene
2008-Oct-07 16:03 UTC
Re: partial_updates does not work when calling save_without_validation!
On Oct 3, 1:15 pm, "Michael Koziarski" <mich...@koziarski.com> wrote:> > Why are you calling save_without_validation!? > > If you want to save without validations the ''public'' api is: > > @object.save(false) >old habits I guess ;) good point! I''ll change those deprecated calls... but it seems like it still makes sense to clear out the changed_attributes should be cleared after an update is run? But I''ll stop there because my original reason for this fix is now invalid. thanks, Adam --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---