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 endless range example to the Active Record Querying guide [ci-skip] #45617

Conversation

ajporterfield
Copy link
Contributor

Summary

Beginless/endless ranges are something I recently discovered. I find them very handy and wish I would have known about them sooner. I think they're definitely worth mentioning in this guide.

@rails-bot rails-bot bot added the docs label Jul 18, 2022
@ajporterfield ajporterfield changed the title Add beginless range example to the Active Record Querying guide Add endless range example to the Active Record Querying guide Jul 18, 2022
Comment on lines 662 to 670
```ruby
Book.where(created_at: (Time.now.midnight - 1.year)..)
```

This would generate SQL like:

```sql
SELECT * FROM books WHERE books.created_at >= '2021-07-18 00:00:00'
```
Copy link
Member

Choose a reason for hiding this comment

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

For better comparison / contrast, what do you think about sticking more closely to the example just above this?

Suggested change
```ruby
Book.where(created_at: (Time.now.midnight - 1.year)..)
```
This would generate SQL like:
```sql
SELECT * FROM books WHERE books.created_at >= '2021-07-18 00:00:00'
```
```ruby
Book.where(created_at: (Time.now.midnight - 1.day)..)
```
This would generate SQL like:
```sql
SELECT * FROM books WHERE books.created_at >= '2008-12-21 00:00:00'
```

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great suggestion @jonathanhefner. I've made that change. Thanks for the review.

@jonathanhefner jonathanhefner changed the title Add endless range example to the Active Record Querying guide Add endless range example to the Active Record Querying guide [ci-skip] Jul 18, 2022
@ajporterfield ajporterfield force-pushed the add-beginless-range-example-to-ar-querying-guide branch from d51a008 to 504887c Compare July 18, 2022 14:43
@jonathanhefner jonathanhefner merged commit bc0f07b into rails:main Jul 18, 2022
@jonathanhefner
Copy link
Member

jonathanhefner commented Jul 18, 2022

Thank you, @ajporterfield! 😄

(Backported to 7-0-stable.)

jonathanhefner added a commit that referenced this pull request Jul 24, 2022
…ple-to-ar-querying-guide

Add endless range example to the Active Record Querying guide [ci-skip]

(cherry picked from commit bc0f07b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants