Class: GraphQL::Sources::ActiveRecordAssociation
- Inherits:
-
Dataloader::Source
- Object
- Dataloader::Source
- GraphQL::Sources::ActiveRecordAssociation
- Defined in:
- lib/graphql/sources/active_record_association.rb
Overview
A class for loading an ActiveRecord association.
Instance Method Summary collapse
- #fetch(records) ⇒ Object
-
#initialize(association) ⇒ ActiveRecordAssociation
constructor
A new instance of ActiveRecordAssociation.
Constructor Details
#initialize(association) ⇒ ActiveRecordAssociation
Returns a new instance of ActiveRecordAssociation.
113 114 115 116 |
# File 'lib/graphql/sources/active_record_association.rb', line 113 def initialize(association) super() @association = association end |
Instance Method Details
#fetch(records) ⇒ Object
119 120 121 122 123 124 |
# File 'lib/graphql/sources/active_record_association.rb', line 119 def fetch(records) preloader = ActiveRecord::Associations::Preloader.new(records: records, associations: [@association]) preloader.call records.map { |record| record.association(@association).target } end |