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: AggregateReflection, AssociationReflection, MacroReflection, ThroughReflection

Class Method Summary collapse

Methods included from ActiveSupport::Concern

append_features, extended, included

Class Method Details

.add_reflection(ar, name, reflection) ⇒ Object



26
27
28
29
30
31
32
# File 'activerecord/lib/active_record/reflection.rb', line 26

def self.add_reflection(ar, name, reflection)
  if reflection.class == AggregateReflection
    ar.aggregate_reflections = ar.aggregate_reflections.merge(name => reflection)
  else
    ar.reflections = ar.reflections.merge(name => reflection)
  end
end

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



13
14
15
16
17
18
19
20
21
22
23
24
# File 'activerecord/lib/active_record/reflection.rb', line 13

def self.create(macro, name, scope, options, ar)
  case macro
  when :has_and_belongs_to_many
    klass = AssociationReflection
  when :has_many, :belongs_to, :has_one
    klass = options[:through] ? ThroughReflection : AssociationReflection
  when :composed_of
    klass = AggregateReflection
  end

  klass.new(macro, name, scope, options, ar)
end