Module: ActiveRecord::Associations

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

Instance Method Summary collapse

Methods included from ActiveSupport::Concern

append_features, class_methods, extended, included

Methods included from ActiveSupport::Autoload

autoload, autoload_at, autoload_under, autoloads, eager_autoload, eager_load!, extended

Instance Method Details

#association(name) ⇒ Object

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



228
229
230
231
232
233
234
235
236
237
238
239
240
# File 'activerecord/lib/active_record/associations.rb', line 228

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



242
243
244
# File 'activerecord/lib/active_record/associations.rb', line 242

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

#initialize_dupObject

:nodoc:



246
247
248
249
# File 'activerecord/lib/active_record/associations.rb', line 246

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

#reloadObject

:nodoc:



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

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