Class: ActiveRecord::PredicateBuilder::AssociationQueryHandler

Inherits:
Object
  • Object
show all
Defined in:
activerecord/lib/active_record/relation/predicate_builder/association_query_handler.rb

Overview

:nodoc:

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(predicate_builder) ⇒ AssociationQueryHandler

Returns a new instance of AssociationQueryHandler.


14
15
16
# File 'activerecord/lib/active_record/relation/predicate_builder/association_query_handler.rb', line 14

def initialize(predicate_builder)
  @predicate_builder = predicate_builder
end

Class Method Details

.value_for(table, column, value) ⇒ Object


4
5
6
7
8
9
10
11
12
# File 'activerecord/lib/active_record/relation/predicate_builder/association_query_handler.rb', line 4

def self.value_for(table, column, value)
  klass = if table.associated_table(column).polymorphic_association? && ::Array === value && value.first.is_a?(Base)
    PolymorphicArrayValue
  else
    AssociationQueryValue
  end

  klass.new(table.associated_table(column), value)
end

Instance Method Details

#call(attribute, value) ⇒ Object


18
19
20
21
22
23
24
25
26
27
28
# File 'activerecord/lib/active_record/relation/predicate_builder/association_query_handler.rb', line 18

def call(attribute, value)
  queries = {}

  table = value.associated_table
  if value.base_class
    queries[table.association_foreign_type.to_s] = value.base_class.name
  end

  queries[table.association_foreign_key.to_s] = value.ids
  predicate_builder.build_from_hash(queries)
end