class SequelMapper::AssociationLoaders::OneToMany
Attributes
foreign_key[R]
key[R]
mapping_name[R]
proxy_factory[R]
type[R]
Public Class Methods
new(type:, mapping_name:, foreign_key:, key:, proxy_factory:)
click to toggle source
# File lib/sequel_mapper/association_loaders.rb, line 4 def initialize(type:, mapping_name:, foreign_key:, key:, proxy_factory:) @type = type @mapping_name = mapping_name @foreign_key = foreign_key @key = key @proxy_factory = proxy_factory @eager_loads = {} end
Public Instance Methods
call(mappings, record, &object_pipeline)
click to toggle source
# File lib/sequel_mapper/association_loaders.rb, line 25 def call(mappings, record, &object_pipeline) mapping = mappings.fetch(mapping_name) proxy_factory.call( query: query(mapping, record), loader: object_pipeline.call(mapping), association_loader: self, ) end
eager_load(dataset, association_name)
click to toggle source
# File lib/sequel_mapper/association_loaders.rb, line 46 def eager_load(dataset, association_name) datastore[mapping.namespace] .where(foreign_key => dataset.select(key)) end
fetch(*args, &block)
click to toggle source
# File lib/sequel_mapper/association_loaders.rb, line 16 def fetch(*args, &block) { key: key, foreign_key: foreign_key, type: type, mapping_name: mapping_name, }.fetch(*args, &block) end
query(mapping, record)
click to toggle source
# File lib/sequel_mapper/association_loaders.rb, line 35 def query(mapping, record) foreign_key_value = record.fetch(key) ->(datastore) { @eager_loads.fetch(record) { datastore[mapping.namespace] .where(foreign_key => foreign_key_value) } } end