Module: Paranoid::ParanoidMethods
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/paranoid/paranoid_methods.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#destroy ⇒ Object
Override the default destroy to allow us to soft delete records.
-
#restore ⇒ Object
Restores the record.
Instance Method Details
#destroy ⇒ Object
Override the default destroy to allow us to soft delete records. This preserves the before_destroy and after_destroy callbacks. Because this is also called internally by Model.destroy_all and the Model.destroy(id), we don’t need to specify those methods separately.
60 61 62 63 64 65 66 67 |
# File 'lib/paranoid/paranoid_methods.rb', line 60 def destroy _run_destroy_callbacks do set_destroyed(field_destroyed.respond_to?(:call) ? field_destroyed.call : field_destroyed) @destroyed = true end self end |
#restore ⇒ Object
Restores the record
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/paranoid/paranoid_methods.rb', line 42 def restore set_destroyed(field_not_destroyed.respond_to?(:call) ? field_not_destroyed.call : field_not_destroyed) self.class.reflect_on_all_associations.each do |association| if association.[:dependent] == :destroy && association.klass.paranoid? (association.klass, association.foreign_key, association.[:primary_key] || 'id', association.) if association.macro.to_s =~ /^has/ end end @destroyed = false self end |