Module: DuckRecord::Associations

Extended by:
ActiveSupport::Autoload, ActiveSupport::Concern
Included in:
Base
Defined in:
lib/duck_record/associations.rb,
lib/duck_record/associations/association.rb,
lib/duck_record/associations/collection_proxy.rb,
lib/duck_record/associations/has_one_association.rb,
lib/duck_record/associations/has_many_association.rb,
lib/duck_record/associations/singular_association.rb,
lib/duck_record/associations/collection_association.rb

Overview

Active Record Has Many Association

Defined Under Namespace

Modules: Builder, ClassMethods Classes: Association, CollectionAssociation, CollectionProxy, HasManyAssociation, HasOneAssociation, SingularAssociation

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.eager_load!Object



42
43
44
45
# File 'lib/duck_record/associations.rb', line 42

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



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/duck_record/associations.rb', line 48

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)


62
63
64
# File 'lib/duck_record/associations.rb', line 62

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

#initialize_dupObject

:nodoc:



66
67
68
69
# File 'lib/duck_record/associations.rb', line 66

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