Class: ActiveRecord::PredicateBuilder::AssociationQueryHandler

Inherits:
Object
  • Object
show all
Defined in:
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.



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

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
13
# File 'lib/active_record/relation/predicate_builder/association_query_handler.rb', line 4

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

  klass.new(associated_table, value)
end

Instance Method Details

#call(attribute, value) ⇒ Object



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

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