Sha256: 769a2d480e6a9b15a64df62c30e84ef385aa2105068e32ab45d0c313664350b8

Contents?: true

Size: 495 Bytes

Versions: 37

Compression:

Stored size: 495 Bytes

Contents

class Graphiti::Sideload::HasMany < Graphiti::Sideload
  def type
    :has_many
  end

  def load_params(parents, query)
    query.hash.tap do |hash|
      hash[:filter] ||= {}
      hash[:filter].merge!(base_filter(parents))
    end
  end

  def base_filter(parents)
    { foreign_key => ids_for_parents(parents).join(',') }
  end

  private

  def child_map(children)
    children.group_by(&foreign_key)
  end

  def children_for(parent, map)
    map[parent.send(primary_key)] || []
  end
end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
graphiti-1.0.rc.2 lib/graphiti/sideload/has_many.rb
graphiti-1.0.rc.1 lib/graphiti/sideload/has_many.rb
graphiti-1.0.beta.23 lib/graphiti/sideload/has_many.rb
graphiti-1.0.beta.22 lib/graphiti/sideload/has_many.rb
graphiti-1.0.beta.21 lib/graphiti/sideload/has_many.rb
graphiti-1.0.beta.20 lib/graphiti/sideload/has_many.rb
graphiti-1.0.beta.19 lib/graphiti/sideload/has_many.rb
graphiti-1.0.beta.18 lib/graphiti/sideload/has_many.rb
graphiti-1.0.beta.17 lib/graphiti/sideload/has_many.rb
graphiti-1.0.beta.16 lib/graphiti/sideload/has_many.rb
graphiti-1.0.beta.15 lib/graphiti/sideload/has_many.rb
graphiti-1.0.beta.14 lib/graphiti/sideload/has_many.rb
graphiti-1.0.beta.13 lib/graphiti/sideload/has_many.rb
graphiti-1.0.beta.12 lib/graphiti/sideload/has_many.rb
graphiti-1.0.beta.11 lib/graphiti/sideload/has_many.rb
graphiti-1.0.beta.10 lib/graphiti/sideload/has_many.rb
graphiti-1.0.beta.9 lib/graphiti/sideload/has_many.rb
graphiti-1.0.beta.8 lib/graphiti/sideload/has_many.rb
graphiti-1.0.beta.7 lib/graphiti/sideload/has_many.rb
graphiti-1.0.beta.6 lib/graphiti/sideload/has_many.rb