I have a model Planning with a start_time attributes.
Say I would like to get all the plannings that are between 9AM and 12PM OR between 6PM and 11PM.
Basically I would do:
Planning.where do
(start_time >= @start_time[0]) & (start_time <= @end_time[0])
|
(start_time >= @start_time[1]) & (start_time <= @end_time[1])
end
The thing is that the number of time slots varies… Any thougths?
If it can help, I use Squeel gem.
Thanks in advance!
You can do whatever you want within the
whereblock; yet you must return the actual query at the end, because this is what will be used as the where clause.So, given an array of times like this:
Here is a verbose solution:
Here is a more clever solution:
Both do generate the following SQL: