Sha256: 44d0167b664a62c5faa88b016eb6b409b0deca70c6b0eb12489c15bbc82d0059
Contents?: true
Size: 652 Bytes
Versions: 4
Compression:
Stored size: 652 Bytes
Contents
# frozen_string_literal: true module SolidusGraphqlApi class BatchLoader # A batch loader for +has_many+ associations. class HasMany < BatchLoader def load graphql_loader_for(object.id, default_value: []) do |object_ids, loader| retrieve_records_for(object_ids).each do |associated_record| loader.call(associated_record.send(reflection.foreign_key)) do |memo| memo << associated_record end end end end private def retrieve_records_for(object_ids) base_relation.where(reflection.foreign_key => object_ids) end end end end
Version data entries
4 entries across 4 versions & 1 rubygems