I have 2 models Show and Booking. A show has many bookings. Each booking has a start_date and end_date. I want to find the shows that either i) have no bookings or ii) have bookings that do not overlap with a time interval [start, end]. So far I have:
Show.joins("LEFT JOIN bookings ON bookings.show_id = shows.id").where("bookings.start_date > ? OR bookings.end_date < ?, end, start)
But it doesn’t return the shows that have no bookings. How can I include the shows that have no bookings in the query result?
Try this: