Module: Immortal

Defined in:
lib/immortal/belongs_to.rb,
lib/immortal.rb,
lib/immortal/belongs_to_builder.rb,
lib/immortal/singular_association.rb

Overview

Include this to add with/onlydeleted accessors for singular associations

Defined Under Namespace

Modules: BelongsTo, ClassMethods, InstanceMethods, SingularAssociation Classes: BelongsToBuilder

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
# File 'lib/immortal.rb', line 5

def self.included(base)
  base.send :extend, ClassMethods
  base.send :include, InstanceMethods
  base.send :include, BelongsTo
  base.class_eval do
    class << self

      # In has_many :through => join_model we have to explicitly add
      # the 'not deleted' scope, otherwise it will take all the rows
      # from the join model
      def has_many_mortal(association_id, options = {}, &extension)
        has_many_immortal(association_id, options, &extension).tap do
          # FIXME This must be re-implemented after the ActiveRecord internals refactor in 3.1
        end
      end

      alias_method :has_many_immortal, :has_many
      alias_method :has_many, :has_many_mortal

      alias :mortal_delete_all :delete_all
      alias :delete_all :immortal_delete_all
    end
  end
end