Module: Queries::Concerns::Polymorphic

Extended by:
ActiveSupport::Concern
Defined in:
lib/queries/concerns/polymorphic.rb

Instance Method Summary (collapse)

Instance Method Details

- (Arel::Node?) matching_polymorphic_ids

TODO: Dry with polymorphic_params

Returns:

  • (Arel::Node, nil)


24
25
26
27
28
29
30
31
32
# File 'lib/queries/concerns/polymorphic.rb', line 24

def matching_polymorphic_ids
  nodes = Queries::Annotator.polymorphic_nodes(polymorphic_ids, self.class.annotating_class)
  return nil if nodes.nil?
  a = nodes.shift
  nodes.each do |b|
    a = a.and(b)
  end
  a
end

- (Object) set_polymorphic_ids(hash)



17
18
19
20
# File 'lib/queries/concerns/polymorphic.rb', line 17

def set_polymorphic_ids(hash)
  @polymorphic_ids = hash.select{|k,v| self.class.annotating_class.related_foreign_keys.include?(k.to_s)} 
  @polymorphic_ids ||= {}
end