Class: Superstore::Associations::HasMany

Inherits:
Association show all
Defined in:
lib/superstore/associations/has_many.rb

Instance Attribute Summary

Attributes inherited from Association

#owner, #reflection

Instance Method Summary collapse

Methods inherited from Association

#association_class, #association_class_name, #initialize, #loaded!, #loaded?, #target, #target=

Constructor Details

This class inherits a constructor from Superstore::Associations::Association

Instance Method Details

#readerObject



4
5
6
7
8
9
10
# File 'lib/superstore/associations/has_many.rb', line 4

def reader
  unless loaded?
    self.target = load_collection
  end

  target
end

#writer(records) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/superstore/associations/has_many.rb', line 12

def writer(records)
  relation = load_collection

  # TODO: Use relation.load_records with Rails 5
  relation.instance_variable_set :@records, records
  relation.instance_variable_set :@loaded, true

  self.target = relation
end