How would you model booked hotel room to guests relationship (in PostgreSQL, if it matters)? A room can have several guests, but at least one.
Sure, one can relate guests to bookings with a foreign key booking_id. But how do you enforce on the DBMS level that a room must have at least one guest?
May be it’s just impossible?
Actually, if you read the question, it states booked hotel rooms. This is quite easy to do as follows:
That way, you can enforce a booked room having at least one guest while the OtherGuests is a 0-or-more relationship. You can’t create a booked room without a guest and you can’t add other guests without the booked room.
It’s the same sort of logic you follow if you want an n-to-n relationship, which should be normalized to a separate table containing a 1-to-n and an n-to-1 with the two tables.