Module: Immortal::BelongsTo

Defined in:
lib/immortal/belongs_to.rb

Overview

Includes this to add association_{with/only}_deleted accessors for belongs_to associations.

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/immortal/belongs_to.rb', line 7

def self.included(base)
  base.class_eval do
    class << self
      # Add with/how_deleted singular association readers
      def belongs_to_mortal(name, scope = nil, options = {})
        reflection = BelongsToBuilder.build(self, name, scope, options)
        ActiveRecord::Reflection.add_reflection self, name, reflection
      end

      alias_method :belongs_to_immortal, :belongs_to
      alias_method :belongs_to, :belongs_to_mortal
    end
  end
end