Clean up old composite key code

Because where now supports tuple querying, we don't need to manually
build queries with where and or statements.
This commit is contained in:
Gannon McGibbon 2023-09-13 16:27:28 -05:00
parent 83f36d5390
commit 1111ec052f
2 changed files with 3 additions and 14 deletions

View File

@ -64,9 +64,7 @@ module ActiveRecord
ids.map! { |id| pk_type.cast(id) }
records = if klass.composite_primary_key?
query_records = ids.map { |values_set| klass.where(primary_key.zip(values_set).to_h) }.inject(&:or)
query_records.index_by do |record|
klass.where(primary_key => ids).index_by do |record|
primary_key.map { |primary_key| record._read_attribute(primary_key) }
end
else

View File

@ -527,12 +527,7 @@ module ActiveRecord
def find_some(ids)
return find_some_ordered(ids) unless order_values.present?
relation = if klass.composite_primary_key?
ids.map { |values_set| where(primary_key.zip(values_set).to_h) }.inject(&:or)
else
where(primary_key => ids)
end
relation = where(primary_key => ids)
relation = relation.select(table[primary_key]) unless select_values.empty?
result = relation.to_a
@ -559,11 +554,7 @@ module ActiveRecord
ids = ids.slice(offset_value || 0, limit_value || ids.size) || []
relation = except(:limit, :offset)
relation = if klass.composite_primary_key?
ids.map { |values_set| relation.where(primary_key.zip(values_set).to_h) }.inject(&:or)
else
relation.where(primary_key => ids)
end
relation = relation.where(primary_key => ids)
relation = relation.select(table[primary_key]) unless select_values.empty?
result = relation.records