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

improve "in_order_of" to allow string column name #45971

Merged
merged 1 commit into from
Sep 9, 2022

Conversation

igorkasyanchuk
Copy link
Contributor

@igorkasyanchuk igorkasyanchuk commented Sep 8, 2022

Motivation / Background

Right now in_order_of doesn't work with the column when it's a string.

[1] pry(main)> User.in_order_of(:id, [1,2,3]).count
  User Count (7.2ms)  SELECT COUNT(*) FROM "users" WHERE "users"."id" IN (1, 2, 3)
=> 3
[2] pry(main)> User.in_order_of('id', [1,2,3]).count
NoMethodError: undefined method `in' for "id":String

        .where!(arel_column.in(values))
                           ^^^
Did you mean?  in?
from /Users/admin/.rvm/gems/ruby-3.1.2/gems/activerecord-7.0.3.1/lib/active_record/relation/query_methods.rb:459:in `in_order_of'

Examples:

image

image

Detail

  • checking the class of the column.

Additional information

Checklist

Before submitting the PR make sure the following are checked:

  • This Pull Request is related to one change. Changes that are unrelated should be opened in separate PRs.
  • There are no typos in commit messages and comments.
  • Commit message has a detailed description of what changed and why. If this PR fixes a related issue include it in the commit message. Ex: [Fix #issue-number]
  • Feature branch is up-to-date with main (if not - rebase it).
  • Pull request only contains one commit for bug fixes and small features. If it's a larger feature, multiple commits are permitted but must be descriptive.
  • Tests are added if you fix a bug or add a feature.
  • CHANGELOG files are updated for the changed libraries if there is a behavior change or additional feature. Minor bug fixes and documentation changes should not be included.
  • PR is not in a draft state.
  • CI is passing.

@rafaelfranca
Copy link
Member

Can you squash your commits?

@rafaelfranca rafaelfranca added the ready PRs ready to merge label Sep 8, 2022
@igorkasyanchuk
Copy link
Contributor Author

@rafaelfranca done

@rafaelfranca rafaelfranca merged commit 556f0b6 into rails:main Sep 9, 2022
@igorkasyanchuk igorkasyanchuk deleted the improve_in_order_of branch September 9, 2022 20:25
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.

2 participants