Validation

mail@pastecode.io avatar
unknown
ruby
a year ago
351 B
2
Indexable
Never
    if property.reservations.where.not(id: id).where(status: 2, start_date: (DateTime.now - 5.years)..end_date, end_date: start_date..(DateTime.now + 5.years)).any?
      errors.add(:start_date, 'There is already a reservation that overlaps these dates')
      errors.add(:end_date, 'There is already a reservation that overlaps these dates')
    end