Module: Superstore::Associations

Extended by:
ActiveSupport::Autoload, ActiveSupport::Concern
Included in:
Base
Defined in:
lib/superstore.rb,
lib/superstore/associations.rb,
lib/superstore/associations/has_one.rb,
lib/superstore/associations/has_many.rb,
lib/superstore/associations/belongs_to.rb,
lib/superstore/associations/reflection.rb,
lib/superstore/associations/association.rb

Defined Under Namespace

Modules: Builder, ClassMethods Classes: Association, BelongsTo, HasMany, HasOne, Reflection

Instance Method Summary collapse

Instance Method Details

#association(name) ⇒ Object

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



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/superstore/associations.rb', line 43

def association(name)
  instance = association_instance_get(name)

  if instance.nil?
    reflection = association_reflections[name]
    instance = reflection.association_class.new(self, reflection)
    association_instance_set(name, instance)
  end

  instance
end