Module: ActiveRecord::Associations

Extended by:
ActiveSupport::Autoload, ActiveSupport::Concern
Included in:
Base
Defined in:
lib/active_record/associations.rb,
lib/active_record/associations/preloader.rb,
lib/active_record/associations/association.rb,
lib/active_record/associations/alias_tracker.rb,
lib/active_record/associations/join_dependency.rb,
lib/active_record/associations/collection_proxy.rb,
lib/active_record/associations/association_scope.rb,
lib/active_record/associations/preloader/has_one.rb,
lib/active_record/associations/preloader/has_many.rb,
lib/active_record/associations/foreign_association.rb,
lib/active_record/associations/has_one_association.rb,
lib/active_record/associations/through_association.rb,
lib/active_record/associations/has_many_association.rb,
lib/active_record/associations/preloader/belongs_to.rb,
lib/active_record/associations/singular_association.rb,
lib/active_record/associations/preloader/association.rb,
lib/active_record/associations/belongs_to_association.rb,
lib/active_record/associations/collection_association.rb,
lib/active_record/associations/join_dependency/join_base.rb,
lib/active_record/associations/join_dependency/join_part.rb,
lib/active_record/associations/preloader/has_one_through.rb,
lib/active_record/associations/preloader/has_many_through.rb,
lib/active_record/associations/has_one_through_association.rb,
lib/active_record/associations/has_many_through_association.rb,
lib/active_record/associations/preloader/through_association.rb,
lib/active_record/associations/preloader/singular_association.rb,
lib/active_record/associations/join_dependency/join_association.rb,
lib/active_record/associations/preloader/collection_association.rb,
lib/active_record/associations/belongs_to_polymorphic_association.rb

Overview

Active Record Belongs To Polymorphic Association

Defined Under Namespace

Modules: Builder, ClassMethods, ForeignAssociation, ThroughAssociation Classes: AliasTracker, Association, AssociationScope, BelongsToAssociation, BelongsToPolymorphicAssociation, CollectionAssociation, CollectionProxy, HasManyAssociation, HasManyThroughAssociation, HasOneAssociation, HasOneThroughAssociation, JoinDependency, Preloader, SingularAssociation

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.eager_load!Object



252
253
254
255
# File 'lib/active_record/associations.rb', line 252

def self.eager_load!
  super
  Preloader.eager_load!
end

Instance Method Details

#association(name) ⇒ Object

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



258
259
260
261
262
263
264
265
266
267
268
269
270
# File 'lib/active_record/associations.rb', line 258

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

:nodoc

Returns:

  • (Boolean)


272
273
274
# File 'lib/active_record/associations.rb', line 272

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

#initialize_dupObject

:nodoc:



276
277
278
279
# File 'lib/active_record/associations.rb', line 276

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

#reloadObject

:nodoc:



281
282
283
284
# File 'lib/active_record/associations.rb', line 281

def reload(*) # :nodoc:
  clear_association_cache
  super
end