Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up old composite key code #49265

Merged
merged 1 commit into from Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -64,9 +64,7 @@ def ids_writer(ids)
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
Expand Down
13 changes: 2 additions & 11 deletions activerecord/lib/active_record/relation/finder_methods.rb
Expand Up @@ -527,12 +527,7 @@ def find_one(id)
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

Expand All @@ -559,11 +554,7 @@ def find_some_ordered(ids)
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

Expand Down