Class: ActiveRecord::PredicateBuilder::AssociationQueryValue

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


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

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


36
37
38
# File 'activerecord/lib/active_record/relation/predicate_builder/association_query_handler.rb', line 36

def associated_table
  @associated_table
end

#valueObject (readonly)

Returns the value of attribute value


36
37
38
# File 'activerecord/lib/active_record/relation/predicate_builder/association_query_handler.rb', line 36

def value
  @value
end

Instance Method Details

#base_classObject


54
55
56
57
58
# File 'activerecord/lib/active_record/relation/predicate_builder/association_query_handler.rb', line 54

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

#idsObject


43
44
45
46
47
48
49
50
51
52
# File 'activerecord/lib/active_record/relation/predicate_builder/association_query_handler.rb', line 43

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