Module: ActiveRecord::Associations
Do not use. This module is for internal use only.
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
-
#association(name)
Returns the association instance for the given name, instantiating it if it doesn’t already exist.
- #association_cached?(name) ⇒ Boolean
- #initialize_dup
-
#association_instance_get(name)
private
Returns the specified association instance if it exists,
nil
otherwise. -
#association_instance_set(name, association)
private
Set the specified association instance.
- #init_internals private
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
# 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
# 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.
# 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.
# 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