You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Booking validation is not really nice. It however works.
The main problem here: you load all the records from database to memory by calling Booking.all. It just does not work with more records. Let's say you have 10.000 bookings. This will fail. It is much better to write custom validator function which sends only one db query.
validate :check_dates_for_me_please
def check_dates_for_me_please
existing_booking = Booking.find_by(room_id: self.room_id, start: ..., end: ...)
errors.add(:room_id, "your record matches other record") if existing_booking
end
The text was updated successfully, but these errors were encountered:
room_bookings/app/models/booking.rb
Line 4 in b0a91bb
Booking validation is not really nice. It however works.
The main problem here: you load all the records from database to memory by calling Booking.all. It just does not work with more records. Let's say you have 10.000 bookings. This will fail. It is much better to write custom validator function which sends only one db query.
The text was updated successfully, but these errors were encountered: