123456789_123456789_123456789_123456789_123456789_

Module: ActiveRecord::Associations

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/associations.rb,
activerecord/lib/active_record/associations/alias_tracker.rb,
activerecord/lib/active_record/associations/association.rb,
activerecord/lib/active_record/associations/association_scope.rb,
activerecord/lib/active_record/associations/belongs_to_association.rb,
activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb,
activerecord/lib/active_record/associations/collection_association.rb,
activerecord/lib/active_record/associations/collection_proxy.rb,
activerecord/lib/active_record/associations/disable_joins_association_scope.rb,
activerecord/lib/active_record/associations/foreign_association.rb,
activerecord/lib/active_record/associations/has_many_association.rb,
activerecord/lib/active_record/associations/has_many_through_association.rb,
activerecord/lib/active_record/associations/has_one_association.rb,
activerecord/lib/active_record/associations/has_one_through_association.rb,
activerecord/lib/active_record/associations/join_dependency.rb,
activerecord/lib/active_record/associations/nested_error.rb,
activerecord/lib/active_record/associations/preloader.rb,
activerecord/lib/active_record/associations/singular_association.rb,
activerecord/lib/active_record/associations/through_association.rb,
activerecord/lib/active_record/associations/join_dependency/join_association.rb,
activerecord/lib/active_record/associations/join_dependency/join_base.rb,
activerecord/lib/active_record/associations/join_dependency/join_part.rb,
activerecord/lib/active_record/associations/preloader/association.rb,
activerecord/lib/active_record/associations/preloader/batch.rb,
activerecord/lib/active_record/associations/preloader/branch.rb,
activerecord/lib/active_record/associations/preloader/through_association.rb

Overview

See ClassMethods for documentation.

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

::ActiveSupport::Autoload - Extended

Instance Method Summary

Class Method Details

.eager_load!

[ GitHub ]

  
# File 'activerecord/lib/active_record/associations.rb', line 44

def self.eager_load!
  super
  Preloader.eager_load!
  JoinDependency.eager_load!
end

Instance Method Details

#association(name)

Returns the association instance for the given name, instantiating it if it doesn’t already exist

[ GitHub ]

  
# File 'activerecord/lib/active_record/associations.rb', line 51

def association(name) # :nodoc:
  association = association_instance_get(name)

  if association.nil?
    unless reflection = self.class._reflect_on_association(name)
      raise AssociationNotFoundError.new(self, name)
    end
    association = reflection.association_class.new(self, reflection)
    association_instance_set(name, association)
  end

  association
end

#association_cached?(name) ⇒ Boolean

[ GitHub ]

  
# File 'activerecord/lib/active_record/associations.rb', line 65

def association_cached?(name) # :nodoc:
  @association_cache.key?(name)
end

#association_instance_get(name) (private)

Returns the specified association instance if it exists, nil otherwise.

[ GitHub ]

  
# File 'activerecord/lib/active_record/associations.rb', line 81

def association_instance_get(name)
  @association_cache[name]
end

#association_instance_set(name, association) (private)

Set the specified association instance.

[ GitHub ]

  
# File 'activerecord/lib/active_record/associations.rb', line 86

def association_instance_set(name, association)
  @association_cache[name] = association
end

#init_internals (private)

[ GitHub ]

  
# File 'activerecord/lib/active_record/associations.rb', line 75

def init_internals
  super
  @association_cache = {}
end

#initialize_dup

[ GitHub ]

  
# File 'activerecord/lib/active_record/associations.rb', line 69

def initialize_dup(*) # :nodoc:
  @association_cache = {}
  super
end