Module: GraphitiGql::ManyToManyExtras

Defined in:
lib/graphiti_gql/graphiti_hax.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.prepended(klass) ⇒ Object



303
304
305
306
307
# File 'lib/graphiti_gql/graphiti_hax.rb', line 303

def self.prepended(klass)
  klass.class_eval do
    attr_reader :join_table_alias, :edge_magic, :edge_resource
  end
end

Instance Method Details

#apply_belongs_to_many_filterObject



316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
# File 'lib/graphiti_gql/graphiti_hax.rb', line 316

def apply_belongs_to_many_filter
  super
  return unless respond_to?(:belongs_to_many_filter) # activerecord
  self_ref = self
  fk_type = parent_resource_class.attributes[:id][:type]
  fk_type = :hash if polymorphic?
  filters = resource_class.config[:filters]

  # Keep the options, apply the eq proc
  if (filter = filters[inverse_filter.to_sym])
    if filter[:operators][:eq].nil?
      filter[:operators][:eq] = proc do |scope, value|
        self_ref.belongs_to_many_filter(scope, value)
      end
    end
  end
end

#initialize(name, opts = {}) ⇒ Object



309
310
311
312
313
314
# File 'lib/graphiti_gql/graphiti_hax.rb', line 309

def initialize(name, opts = {})
  @join_table_alias = opts[:join_table_alias]
  @edge_magic = opts[:edge_magic] == false ? false : true
  @edge_resource = opts[:edge_resource]
  super
end