Sha256: fbb293ac5e9e216edae02d0ed71d61710c85d204339914890fd93c1877d85b16
Contents?: true
Size: 657 Bytes
Versions: 9
Compression:
Stored size: 657 Bytes
Contents
class Graphiti::Sideload::ManyToMany < Graphiti::Sideload::HasMany def type :many_to_many end def through foreign_key.keys.first end def true_foreign_key foreign_key.values.first end def base_filter(parents) { true_foreign_key => ids_for_parents(parents).join(',') } end def infer_foreign_key raise 'You must explicitly pass :foreign_key for many-to-many relationships, or override in subclass to return a hash.' end def assign_each(parent, children) children.select do |c| match = ->(ct) { ct.send(true_foreign_key) == parent.send(primary_key) } c.send(through).any?(&match) end end end
Version data entries
9 entries across 9 versions & 1 rubygems