Class: GraphitiGql::Loaders::HasMany
- Defined in:
- lib/graphiti_gql/loaders/has_many.rb
Instance Method Summary collapse
Methods inherited from Many
factory, #initialize, #perform
Constructor Details
This class inherits a constructor from GraphitiGql::Loaders::Many
Instance Method Details
#assign(parent_records, proxy) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/graphiti_gql/loaders/has_many.rb', line 4 def assign(parent_records, proxy) records = proxy.data foreign_key = @sideload.foreign_key config = @sideload.resource.attributes[foreign_key] if config && config[:alias] foreign_key = config[:alias] end map = records.group_by { |record| record.send(foreign_key) } parent_records.each do |pr| data = [map[pr.send(@sideload.primary_key)] || [], proxy] fulfill(pr, data) end end |