Flinn Mueller on 15 Feb 2007 03:10:56 -0000


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PhillyOnRails] Looking for help overriding clear_old_version in acts_as_versioned


On Feb 14, 2007, at 6:29 PM, Mike Zornek wrote:

This is really a syntax question as I'm not sure how to override a method
that is part of a Module.

Add this to your config/environment.rb

module ActiveRecord
  module Acts
    module Versioned
      module ClassMethods
        def acts_as_paranoid_versioned
          acts_as_paranoid
          acts_as_versioned

          # protect the versioned model
          self.versioned_class.class_eval do
            def self.delete_all(conditions = nil); return; end
          end
        end
      end
    end
  end
end

Then instead of both:
acts_as_paranoid
acts_as_versioned

Add this in your class:
acts_as_paranoid_versioned


The ruby code is here:

http://svn.techno-weenie.net/projects/plugins/acts_as_versioned/lib/ acts_as_
versioned.rb


The method I need to remove (ie: replace with a method that does nothing) is
`clear_old_versions`.


Clear old versions only runs after_save, and it's only to prune versions in excess of the limit you set. The reason the old versions get deleted is because they are :dependent => :delete_all to the original model and get zapped before_destroy. So the solution is to override versioned_class.delete_all.

With this setup, the versioned record doesn't pick up deleted_at. My guess is (I haven't tested it) if you wanted to revive the record, it would be easier to revert to the record without deleted_at than revert and clear deleted_at so the record is alive again. Ymmv.
_______________________________________________
To unsubscribe or change your settings, visit:
http://lists.phillyonrails.org/mailman/listinfo/talk