Class: ActiveRecord::PredicateBuilder::PolymorphicArrayValue

Inherits:
Object
  • Object
show all
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/relation/predicate_builder/polymorphic_array_value.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(associated_table, values) ⇒ PolymorphicArrayValue

Returns a new instance of PolymorphicArrayValue.



6
7
8
9
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/relation/predicate_builder/polymorphic_array_value.rb', line 6

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

Instance Method Details

#queriesObject



11
12
13
14
15
16
17
18
19
20
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/relation/predicate_builder/polymorphic_array_value.rb', line 11

def queries
  return [ associated_table.join_foreign_key => values ] if values.empty?

  type_to_ids_mapping.map do |type, ids|
    query = {}
    query[associated_table.join_foreign_type] = type if type
    query[associated_table.join_foreign_key] = ids
    query
  end
end