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
Recommend using where
with ranges
#316
Conversation
337bb2b
to
5bd06b2
Compare
README.adoc
Outdated
# okish - there is no range syntax that would denote inclusion on one end and | ||
# exclusion on another. | ||
Customer.where("purchases_count > :min AND purchases_count <= :max", min: 0, max: 5) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note to self: extra blank line
b2442c3
to
bd73b49
Compare
Customer.where("purchases_count > :min AND purchases_count <= :max", min: 0, max: 5) | ||
---- | ||
|
||
NOTE: Rails 6.0 or later is required for endless range Ruby 2.6 syntax, and Rails 6.0.3 for beginless range Ruby 2.7 syntax. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'created_at >= :start_date AND created_at <= :end_date', | ||
start_date: params[:start_date], end_date: params[:end_date] | ||
'orders_count >= :min_orders_count AND country_code = :country_code', | ||
min_orders_count: params[:min_orders_count], country_code: params[:country_code] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this change is not related to the addition of Where with Ranges
new rule, it could be opened as a separate PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On a second thought, I've made this change to make Named Placeholder example not to go against the new Where with Ranges.
Without this, it would have to be written as:
Client.where(created_at: params[:start_date]..params[:end_date])
which defeats the purpose of being a good example for Named Placeholder.
bd73b49
to
0026eee
Compare
Looks good. Thanks! |
Related
rubocop-rails
ticket.Keep in mind (added this an a "okish" example):
foo: bar..
replaces'foo >= ?', bar
foo: bar...
also replaces'foo >= ?', bar
(not'foo' > ?', bar
)foo: ..bar
replaces'foo <= ?', bar
foo: ...bar
replaces'foo < ?', bar
But there is nothing that would replace a set of conditions where one is inclusive, and the other is exclusive:
'foo >= ? AND foo < ?'
Real-world examples (gathered from
real-world-rspec
):Specifically open ranges: