Module: ActsAsParanoid::Relation

Defined in:
lib/acts_as_paranoid/relation.rb

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/acts_as_paranoid/relation.rb', line 5

def self.included(base)
  base.class_eval do
    def paranoid?
      klass.try(:paranoid?) ? true : false
    end

    def paranoid_deletion_attributes
      { klass.paranoid_column => klass.delete_now_value }
    end

    alias_method :orig_delete_all, :delete_all
    def delete_all!(conditions = nil)
      if conditions
        where(conditions).delete_all!
      else
        orig_delete_all
      end
    end

    def delete_all(conditions = nil)
      if paranoid?
        where(conditions).update_all(paranoid_deletion_attributes)
      else
        delete_all!(conditions)
      end
    end

    def destroy_fully!(id_or_array)
      where(primary_key => id_or_array).orig_delete_all
    end
  end
end