Module: ActiveRecord::Reflection

Defined in:
lib/active_record/reflection.rb

Overview

:nodoc:

Defined Under Namespace

Modules: ClassMethods Classes: AggregateReflection, AssociationReflection, MacroReflection

Class Method Summary collapse

Class Method Details

.append_features(base) ⇒ Object



3
4
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
# File 'lib/active_record/reflection.rb', line 3

def self.append_features(base)
  super
  base.extend(ClassMethods)

  base.class_eval do
    class << self
      alias_method :composed_of_without_reflection, :composed_of

      def composed_of_with_reflection(part_id, options = {})
        composed_of_without_reflection(part_id, options)
        write_inheritable_array "aggregations", [ AggregateReflection.new(:composed_of, part_id, options, self) ]
      end

      alias_method :composed_of, :composed_of_with_reflection          
    end
  end
  
  for association_type in %w( belongs_to has_one has_many has_and_belongs_to_many )
    base.module_eval <<-"end_eval"
      class << self
        alias_method :#{association_type}_without_reflection, :#{association_type}

        def #{association_type}_with_reflection(association_id, options = {})
          #{association_type}_without_reflection(association_id, options)
          write_inheritable_array "associations", [ AssociationReflection.new(:#{association_type}, association_id, options, self) ]
        end

        alias_method :#{association_type}, :#{association_type}_with_reflection          
      end
    end_eval
  end
end