Class: ActiveRecord::PredicateBuilder::PolymorphicArrayValue
Do not use. This class is for internal use only.
Class Method Summary
Instance Attribute Summary
Instance Method Summary
Constructor Details
.new(associated_table, values) ⇒ PolymorphicArrayValue
[ GitHub ]
Instance Attribute Details
#associated_table
[ GitHub ]
# File 'activerecord/lib/active_record/relation/predicate_builder/polymorphic_array_value.rb', line 23
attr_reader :associated_table, :values
#values
[ GitHub ]
# File 'activerecord/lib/active_record/relation/predicate_builder/polymorphic_array_value.rb', line 23
attr_reader :associated_table, :values
Instance Method Details
#convert_to_id(value)
[ GitHub ]
#klass(value)
[ GitHub ]
# File 'activerecord/lib/active_record/relation/predicate_builder/polymorphic_array_value.rb', line 36
def klass(value)
if value.is_a?(Base)
value.class
elsif value.is_a?(Relation)
value.model
end
end
#primary_key(value)
[ GitHub ]
# File 'activerecord/lib/active_record/relation/predicate_builder/polymorphic_array_value.rb', line 32
def primary_key(value)
associated_table.join_primary_key(klass(value))
end
#type_to_ids_mapping
[ GitHub ]
# File 'activerecord/lib/active_record/relation/predicate_builder/polymorphic_array_value.rb', line 25
def type_to_ids_mapping
default_hash = Hash.new { |hsh, key| hsh[key] = [] }
values.each_with_object(default_hash) do |value, hash|
hash[klass(value)&.polymorphic_name] << convert_to_id(value)
end
end