Agis A.
2014-Feb-05 11:48 UTC
SQL adapter convert Date objects automatically to DateTime ranges.
When we want to find records created on a specific day, we have to do it
like this:
> User.where(created_at:
(Date.yesterday.beginning_of_day..Date.yesterday.end_of_day)).to_sql
=> "SELECT `users`.* FROM `users` WHERE (`users`.`created_at`
BETWEEN
'2014-01-28 00:00:00' AND '2014-01-28 23:59:59')"
because if we don't supply a range the following will be queried:
> User.where(created_at: Date.yesterday).to_sql
=> "SELECT `users`.* FROM `users` WHERE `users`.`created_at` =
'2014-01-28'"
What if we patched AR so when we query as I do in the 2nd case, it treats
it like it would do in the 1st query?
So when I say:
> User.where(created_at: Date.yesterday)
It would bring me all the records that were created yesterday (from the
beginning to the end of date).
Let me know if this makes sense and is feasible, and I can prepare a PR.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to rubyonrails-core+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-core@googlegroups.com.
Visit this group at http://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/groups/opt_out.