So, I have an Event
model that has a starts_at
and a ends_at
column and I want to find events that take place in a range of dates.
I've come up with this named_scope
(range
is typically a month):
named_scope :in_range, lambda { |range|
{:conditions => [
'starts_at BETWEEN ? AND ? OR ends_at BETWEEN ? AND ?',
range.first, range.last, range.first, range.last]} }
Which works as expected.
But if an event starts the month before and ends the month after the range it won't show. Is there any way to find those events in a proper way?