I have an application that involves absence records for employees.
I need to ensure that the start and end dates for each record don\'t overlap.
So for example,
As a modification to the accepted answer, here's an overlaps scope that will work for DBs that don't understand DATEDIFF
scope :overlaps, ->(start_date, end_date) do
where "((start_date <= ?) and (end_date >= ?))", end_date, start_date
end
This draws on the solution for Determine Whether Two Date Ranges Overlap