Module: ActiveRecord::Reflection

Extended by:
ActiveSupport::Concern
Included in:
Base
Defined in:
activerecord/lib/active_record/reflection.rb

Overview

Active Record Reflection

Defined Under Namespace

Modules: ClassMethods Classes: AbstractReflection, AggregateReflection, AssociationReflection, BelongsToReflection, HasAndBelongsToManyReflection, HasManyReflection, HasOneReflection, MacroReflection, PolymorphicReflection, RuntimeReflection, ThroughReflection

Class Method Summary collapse

Methods included from ActiveSupport::Concern

append_features, class_methods, extended, included

Class Method Details

.add_aggregate_reflection(ar, name, reflection) ⇒ Object



38
39
40
# File 'activerecord/lib/active_record/reflection.rb', line 38

def self.add_aggregate_reflection(ar, name, reflection)
  ar.aggregate_reflections = ar.aggregate_reflections.merge(name.to_s => reflection)
end

.add_reflection(ar, name, reflection) ⇒ Object



34
35
36
# File 'activerecord/lib/active_record/reflection.rb', line 34

def self.add_reflection(ar, name, reflection)
  ar._reflections = ar._reflections.merge(name.to_s => reflection)
end

.create(macro, name, scope, options, ar) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'activerecord/lib/active_record/reflection.rb', line 16

def self.create(macro, name, scope, options, ar)
  klass = case macro
          when :composed_of
            AggregateReflection
          when :has_many
            HasManyReflection
          when :has_one
            HasOneReflection
          when :belongs_to
            BelongsToReflection
          else
            raise "Unsupported Macro: #{macro}"
          end

  reflection = klass.new(name, scope, options, ar)
  options[:through] ? ThroughReflection.new(reflection) : reflection
end