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

Do not mutate relation when implicitly selecting a primary key in ActiveRecord.find #45931

Merged
merged 1 commit into from
Sep 2, 2022

Conversation

fatkodima
Copy link
Member

Follow up to #45695.

cc @byroot

Comment on lines +483 to +485
relation = where(primary_key => ids)
relation = relation.select(table[primary_key]) unless select_values.empty?
result = relation.to_a
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we even need it here? find_some doesn't need the primary key, does it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not need them, but I tried to make it consistent, so both of them always select ids.
Having these ids, we can also slightly improve the error reporting here:

raise_record_not_found_exception!(ids, result.size, expected_size)

by passing not found ids.

Wdyt?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, that works for me.

@byroot byroot merged commit fa50226 into rails:main Sep 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants