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

Add option only_values on in_order_of #51761

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

igordepolli
Copy link

@igordepolli igordepolli commented May 7, 2024

Motivation / Background

This Pull Request has been created because currently, in_order_of method always use where clause to filter the results only with the values specified in values. Sometimes, we only want to put some values as priority in the sorting but we want the entire search scope without caring about the rest of the sorting. The propose here is add an option to specify to filter scope by values or not.

Detail

This Pull Request changes:

order = [3, 4, 1]

# Without specify option
Post.in_order_of(:id, order).to_sql
# SELECT 
  # "posts".* FROM "posts" 
# WHERE 
  # "posts"."id" IN (3, 4, 1) 
# ORDER BY 
  # CASE WHEN "posts"."id" = 3 THEN 1 WHEN "posts"."id" = 4 THEN 2 WHEN "posts"."id" = 1 THEN 3 END ASC

# With option seted to false
Post.in_order_of(:id, order, only_values: false)
# SELECT 
  # "posts".* FROM "posts" 
# ORDER BY 
  # CASE WHEN "posts"."id" = 3 THEN 1 WHEN "posts"."id" = 4 THEN 2 WHEN "posts"."id" = 1 THEN 3 ELSE 4 END ASC

Checklist

Before submitting the PR make sure the following are checked:

  • This Pull Request is related to one change. Unrelated changes should be opened in separate PRs.
  • 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]
  • Tests are added or updated 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.

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

1 participant