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,
While juanpastas solution is correct, it will be valid for creation of records, but can lead to false negative validations on updates.
If you need to edit an existing record, say the range is 2014-03-13..2014-06-12 and you want to reduce it to 2014-03-13..2014-04-12, you'll get an overlap error because it is checking AGAINST itself.
def siblings
Absence_users.where('user_id = ? AND id != ?', user_id, self)
end
will obviate that shortcoming. (Dave T's addition should also be followed, being DB-agnostic.)