class Terrestrial::OneToManyAssociation

Attributes

foreign_key[R]
key[R]
mapping_name[R]
order[R]
proxy_factory[R]

Public Class Methods

new(mapping_name:, foreign_key:, key:, order:, proxy_factory:) click to toggle source
# File lib/terrestrial/one_to_many_association.rb, line 5
def initialize(mapping_name:, foreign_key:, key:, order:, proxy_factory:)
  @mapping_name = mapping_name
  @foreign_key = foreign_key
  @key = key
  @order = order
  @proxy_factory = proxy_factory
end

Public Instance Methods

build_proxy(data_superset:, loader:, record:) click to toggle source
# File lib/terrestrial/one_to_many_association.rb, line 30
def build_proxy(data_superset:, loader:, record:)
 proxy_factory.call(
    query: build_query(data_superset, record),
    loader: loader,
    mapping_name: mapping_name,
  )
end
build_query((superset), record) click to toggle source
# File lib/terrestrial/one_to_many_association.rb, line 63
def build_query((superset), record)
  order.apply(
    superset.where(foreign_key => record.fetch(key))
  )
end
delete(parent_record, collection, depth, &block)
Alias for: dump
dump(parent_record, collection, depth, &block) click to toggle source
# File lib/terrestrial/one_to_many_association.rb, line 38
def dump(parent_record, collection, depth, &block)
  foreign_key_pair = {
    foreign_key => parent_record.fetch(key),
  }

  collection.flat_map { |associated_object|
    block.call(mapping_name, associated_object, foreign_key_pair, depth + depth_modifier)
  }
end
Also aliased as: delete
eager_superset((superset), (associated_dataset)) click to toggle source
# File lib/terrestrial/one_to_many_association.rb, line 53
def eager_superset((superset), (associated_dataset))
  [
    Dataset.new(
      superset.where(
        foreign_key => associated_dataset.select(key)
      ).to_a
    )
  ]
end
extract_foreign_key(_record) click to toggle source
# File lib/terrestrial/one_to_many_association.rb, line 49
def extract_foreign_key(_record)
  {}
end
local_foreign_keys() click to toggle source
# File lib/terrestrial/one_to_many_association.rb, line 21
def local_foreign_keys
  []
end
mapping_names() click to toggle source
# File lib/terrestrial/one_to_many_association.rb, line 13
def mapping_names
  [mapping_name]
end
outgoing_foreign_keys() click to toggle source
# File lib/terrestrial/one_to_many_association.rb, line 17
def outgoing_foreign_keys
  [foreign_key]
end

Private Instance Methods

depth_modifier() click to toggle source
# File lib/terrestrial/one_to_many_association.rb, line 71
def depth_modifier
  +1
end