I’m building an application to let college students search for housing. My model includes a Room table with the room dimensions, whether it’s reserved for hall staff, and its room number, among other things. However, some rooms participate in “suites” of 2-8 rooms. How would I model that?
I was considering a suite_id column in the Room table, with NULL allowed to account for (the majority of) the rooms that aren’t suites. It seems like there should be a more elegant way to do things, though.
As for what I want to do with the data, I want to be able to check if a room is part of a suite, and I want to be able to query for all suites (optionally limiting by size).
Any advice would be much appreciated!
That schema works fine.
To check if a room is part of a suite, check if the column is null or not in your application.
To query for all suites, select rows
WHERE suite_id IS NOT NULL, and limit by size byGROUP BY suite_id HAVING COUNT(*) = number_of_rooms_you_want.Though the syntax might be slightly different depending what RDBMS you’re using. You didn’t tag the question with any.