Appointments have two fields, an at (a datetime) and minutes (integer, length of appointment)
appointment_a: at = "2015-04-02 21:00:00", and minutes = 60, which already exists.
I'm trying to create appointment_b, where at = "2015-04-02 21:30:00", and minutes = 60.
This is a validation in the Appointment model:
def check_overlap
from = appointment_a.at
to = appointment_a.minutes * 60 + appointment_a.at
if Appointment.where('at >= ? AND at + minutes * 60 >= ?', from, to).emtpy? == false
errors.add(:at, (" field will cause overlap between existing appointments "))
end
end
Why is this not adding errors?