class Superstore::Associations::HasMany

Public Instance Methods

reader() click to toggle source
# File lib/superstore/associations/has_many.rb, line 4
def reader
  unless loaded?
    self.target = load_collection
  end

  target
end
set_inverse_instance(record) click to toggle source
# File lib/superstore/associations/has_many.rb, line 22
def set_inverse_instance(record)
  return unless reflection.inverse_name

  inverse = record.association(reflection.inverse_name)
  inverse.target = owner
end
writer(records) click to toggle source
# 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

Private Instance Methods

inverse_of() click to toggle source
# File lib/superstore/associations/has_many.rb, line 31
def inverse_of
  return unless reflection.inverse_name

  @inverse_of ||= association_class.reflect_on_association reflection.inverse_name
end
load_collection() click to toggle source
# File lib/superstore/associations/has_many.rb, line 37
def load_collection
  AssociationScope.new(association_class, self).where("document ->> '#{reflection.foreign_key}' = '#{owner.try(reflection.primary_key)}'")
end