Module: SoftDestroyable
- Defined in:
- lib/soft_destroyable.rb,
lib/soft_destroyable/table_definition.rb,
lib/soft_destroyable/is_soft_destroyable.rb
Overview
Allows one to annotate an ActiveRecord module as being soft_destroyable.
This changes the behavior of the destroy
method to being a soft-destroy, which will set the deleted_at
attribute to Time.now
, and the deleted
attribute to true
It exposes the revive
method to reverse the effects of destroy
(for :dependent => :destroy associations only). It also exposes the destroy!
method which can be used to really destroy an object and it’s associations.
revive
will not cascade revive child associations which have been destroyed by actions other a destroy of the parent. This requires the column attribute revive_with_parent
.
Standard ActiveRecord destroy callbacks are not called, however you can override before_soft_destroy
, after_soft_destroy
, and before_destroy!
on your soft_destroyable models.
Standard ActiveRecord dependent options :destroy, :restrict, :nullify, :delete_all, and :delete are supported. revive
will not undo the effects of nullify
, delete_all
, and delete
. restrict
is not effected by the deleted?
state. In other words, deleted child models will still restrict destroying the parent.
The delete
operation is not modified by this module.
The operations: destroy
, destroy!
, and revive
are automatically delegated to the dependent association records. in a single transaction.
Examples:
class Parent
has_many :children, :dependent => :restrict
has_many :animals, :dependent => :nullify
soft_destroyable
Author: Michael Kintzer
Defined Under Namespace
Modules: ClassMethods, InstanceMethods, IsSoftDestroyable, SingletonMethods, TableDefinition Classes: SoftDestroyError
Class Method Summary collapse
Class Method Details
.included(base) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/soft_destroyable.rb', line 38 def self.included(base) base.class_eval do extend ClassMethods extend IsSoftDestroyable end end |