123456789_123456789_123456789_123456789_123456789_

Module: ActiveRecord::Reflection

Do not use. This module is for internal use only.
Relationships & Source Files
Namespace Children
Modules:
Classes:
Extension / Inclusion / Inheritance Descendants
Included In:
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Defined in: activerecord/lib/active_record/reflection.rb

Class Method Summary

::ActiveSupport::Concern - Extended

class_methods

Define class methods from given block.

included

Evaluate given block in context of base class, so that you can write class macros here.

prepended

Evaluate given block in context of base class, so that you can write class macros here.

append_features, prepend_features

DSL Calls

included

[ GitHub ]


10
11
12
13
14
15
# File 'activerecord/lib/active_record/reflection.rb', line 10

included do
  class_attribute :_reflections, instance_writer: false, default: {}
  class_attribute :aggregate_reflections, instance_writer: false, default: {}
  class_attribute :automatic_scope_inversing, instance_writer: false, default: false
  class_attribute :automatically_invert_plural_associations, instance_writer: false, default: false
end

Class Method Details

.add_aggregate_reflection(ar, name, reflection)

[ GitHub ]

  
# File 'activerecord/lib/active_record/reflection.rb', line 29

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

.add_reflection(ar, name, reflection)

[ GitHub ]

  
# File 'activerecord/lib/active_record/reflection.rb', line 23

def add_reflection(ar, name, reflection)
  ar.clear_reflections_cache
  name = name.to_sym
  ar._reflections = ar._reflections.except(name).merge!(name => reflection)
end

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

[ GitHub ]

  
# File 'activerecord/lib/active_record/reflection.rb', line 18

def create(macro, name, scope, options, ar)
  reflection = reflection_class_for(macro).new(name, scope, options, ar)
  options[:through] ? ThroughReflection.new(reflection) : reflection
end

.reflection_class_for(macro) (private)

[ GitHub ]

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

def reflection_class_for(macro)
  case macro
  when :composed_of
    AggregateReflection
  when :has_many
    HasManyReflection
  when :has_one
    HasOneReflection
  when :belongs_to
    BelongsToReflection
  else
    raise "Unsupported Macro: #{macro}"
  end
end