Class: SolidusGraphqlApi::BatchLoader::BelongsTo

Inherits:
SolidusGraphqlApi::BatchLoader show all
Defined in:
lib/solidus_graphql_api/batch_loader/belongs_to.rb

Overview

A batch loader for belongs_to associations.

Constant Summary

Constants inherited from SolidusGraphqlApi::BatchLoader

LOADER_CLASSES

Instance Attribute Summary

Attributes inherited from SolidusGraphqlApi::BatchLoader

#object, #options, #reflection

Instance Method Summary collapse

Methods inherited from SolidusGraphqlApi::BatchLoader

for, #initialize

Constructor Details

This class inherits a constructor from SolidusGraphqlApi::BatchLoader

Instance Method Details

#loadObject



7
8
9
10
11
12
13
# File 'lib/solidus_graphql_api/batch_loader/belongs_to.rb', line 7

def load
  graphql_loader_for(object.send(reflection.foreign_key)) do |object_ids, loader|
    retrieve_records_for(object_ids).each do |record|
      loader.call(record.send(association_primary_key), record)
    end
  end
end