class Graphiti::Sideload::ManyToMany

Public Instance Methods

apply_belongs_to_many_filter() click to toggle source
# File lib/graphiti/sideload/many_to_many.rb, line 35
def apply_belongs_to_many_filter
  self_ref = self
  fk_type = parent_resource_class.attributes[:id][:type]
  fk_type = :hash if polymorphic?
  # Do not recreate if filter already exists
  unless resource_class.config[:filters].has_key?(inverse_filter.to_sym)
    resource_class.filter inverse_filter, fk_type do
      eq do |scope, value|
        self_ref.belongs_to_many_filter(scope, value)
      end
    end
  end
end
assign_each(parent, children) click to toggle source
# File lib/graphiti/sideload/many_to_many.rb, line 49
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
base_filter(parents) click to toggle source
# File lib/graphiti/sideload/many_to_many.rb, line 18
def base_filter(parents)
  {true_foreign_key => parent_filter(parents)}
end
infer_foreign_key() click to toggle source
# File lib/graphiti/sideload/many_to_many.rb, line 22
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
inverse_filter() click to toggle source
# File lib/graphiti/sideload/many_to_many.rb, line 14
def inverse_filter
  @inverse_filter || true_foreign_key
end
performant_assign?() click to toggle source
# File lib/graphiti/sideload/many_to_many.rb, line 26
def performant_assign?
  false
end
polymorphic?() click to toggle source

Override in subclass

# File lib/graphiti/sideload/many_to_many.rb, line 31
def polymorphic?
  false
end
through() click to toggle source
# File lib/graphiti/sideload/many_to_many.rb, line 6
def through
  foreign_key.keys.first
end
true_foreign_key() click to toggle source
# File lib/graphiti/sideload/many_to_many.rb, line 10
def true_foreign_key
  foreign_key.values.first
end
type() click to toggle source
# File lib/graphiti/sideload/many_to_many.rb, line 2
def type
  :many_to_many
end