Class: ActiveRecord::PredicateBuilder::AssociationQueryValue

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

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(associated_table, value) ⇒ AssociationQueryValue

Returns a new instance of AssociationQueryValue.



41
42
43
44
# File 'lib/active_record/relation/predicate_builder/association_query_handler.rb', line 41

def initialize(associated_table, value)
  @associated_table = associated_table
  @value = value
end

Instance Attribute Details

#associated_tableObject (readonly)

Returns the value of attribute associated_table.



39
40
41
# File 'lib/active_record/relation/predicate_builder/association_query_handler.rb', line 39

def associated_table
  @associated_table
end

#valueObject (readonly)

Returns the value of attribute value.



39
40
41
# File 'lib/active_record/relation/predicate_builder/association_query_handler.rb', line 39

def value
  @value
end

Instance Method Details

#base_classObject



57
58
59
60
61
# File 'lib/active_record/relation/predicate_builder/association_query_handler.rb', line 57

def base_class
  if associated_table.polymorphic_association?
    @base_class ||= polymorphic_base_class_from_value
  end
end

#idsObject



46
47
48
49
50
51
52
53
54
55
# File 'lib/active_record/relation/predicate_builder/association_query_handler.rb', line 46

def ids
  case value
  when Relation
    value.select(primary_key)
  when Array
    value.map { |v| convert_to_id(v) }
  else
    convert_to_id(value)
  end
end