Class: GraphitiGql::Loaders::ManyToMany

Inherits:
Many
  • Object
show all
Defined in:
lib/graphiti_gql/loaders/many_to_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
# File 'lib/graphiti_gql/loaders/many_to_many.rb', line 4

def assign(parent_records, proxy)
  thru = @sideload.foreign_key.keys.first
  fk = @sideload.foreign_key[thru]
  add_join_table_magic(proxy)
  records = proxy.data
  parent_records.each do |pr|
    corresponding = records.select do |record|
      record.send(:"_edge_#{fk}") == pr.send(@sideload.primary_key)
    end
    fulfill(pr, [corresponding, proxy])
  end
end