# Booking system

**URL:** <https://www.ruby-forum.com/t/booking-system/69635>\
**Category:** Rails\
**Created:** [February 17, 2006, 11:05am UTC](https://www.ruby-forum.com/t/booking-system/69635 "2006-02-17T11:05:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![papipo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f04885/32.png) [@papipo](https://www.ruby-forum.com/u/papipo)\
**Post date:** [February 17, 2006, 11:05am UTC](https://www.ruby-forum.com/t/booking-system/69635/1 "2006-02-17T11:05:32Z")

</div>

Hi!

I’m planning a booking system in rails, and I have the following issue:

There will be room\_types. I can implement this with STI in the rooms  
table, or with a separate table room\_types. Each room type will have its  
special features.  
For example:

Room::SingleRoom # For 1 person  
Room::DoubleRoom # Simply for 2 people  
Room::DoubleRoom::SingleDoubleRoom # If only for 1 person will be  
cheaper  
Room::DoubleRoom::ExtraBedDoubleRoom # 3 people can use it (more  
expensive)  
Room::Apartment # For example, between 4-6 people, with different prices  
each  
etc…

There is another approach, with a room\_types table. It can take care of  
the capacities of the different rooms, allowing the customers to search.  
The table structure can be something like:

name: the RoomType name  
default\_capacity: The mainly used capacity (2 In case of  
ExtraBedDoubleRoom)  
maximum\_capacity: The room allows more people (3 In case of  
ExtraBedDoubleRoom)  
minimum\_capacity: If the customer uses this type of room but with a  
value lesser than this, will pay the price assigned to this minimum (2  
In case of ExtraBedDoubleRoom)

Remember that the system must be searchable, so the typical STI solution  
doesn’t fit well, since I must then specify the capacities in the code!  
Some kind of hybrid makes more sense to me. Is there any other approach?  
How do you would do it?

Thanks!

---

<div class="post-metadata">

**Author:** ![papipo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f04885/32.png) [@papipo](https://www.ruby-forum.com/u/papipo)\
**Post date:** [February 17, 2006, 1:18pm UTC](https://www.ruby-forum.com/t/booking-system/69635/2 "2006-02-17T13:18:23Z")

</div>

Rodrigo

What about using tags?

Alain

---

<div class="post-metadata">

**Author:** ![papipo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f04885/32.png) [@papipo](https://www.ruby-forum.com/u/papipo)\
**Post date:** [February 20, 2006, 9:53am UTC](https://www.ruby-forum.com/t/booking-system/69635/3 "2006-02-20T09:53:23Z")

</div>

On 17 Feb 2006, at 10:05 am, Rodrigo A. wrote:

> Some kind of hybrid makes more sense to me. Is there any other  
> approach?  
> How do you would do it?

I’d go with your room\_types idea:

> name: the RoomType name  
> default\_capacity: The mainly used capacity (2 In case of  
> ExtraBedDoubleRoom)  
> maximum\_capacity: The room allows more people (3 In case of  
> ExtraBedDoubleRoom)  
> minimum\_capacity: If the customer uses this type of room but with a  
> value lesser than this, will pay the price assigned to this minimum (2  
> In case of ExtraBedDoubleRoom)

There’s no reason that these different room types have to be  
different classes in your Ruby code. As you point out, you would end  
up hard-coding the room types and capacities into the application. If  
they ever want to change the room types, or add/delete one (and you  
know they will!), you’ll have to change the code. Using a room\_types  
table makes this kind of thing easy.

The other way to think about is this: you only need to use STI if the  
different classes are going to behave in different ways. The classic  
example is ‘Employee \< Person’ and ‘Manager \< Person’. These things  
are both obviously people, so they’ll have some common things like  
full\_name(). But in the day-to-day activities of your application,  
they’ll be _doing_ fundamentally different things (your Managers  
might manage() some projects, while your Employees might carry\_out()  
some Tasks and be managed\_by(pointy\_haired\_boss).) That’s why you  
want different Ruby classes for them.

With Rooms, on the other hand, each of your different ‘types’ of room  
(double rooms, single rooms, double rooms with an extra bed, etc.)  
will have a few _properties_ that are different (i.e. max\_capacity of  
1 or 2 or 3), but they will all _behave_ in basically the same way.  
They’ll have\_many bookings placed against them, they’ll be available?  
(tomorrow), etc. There’s no benefit to having different classes for  
the different types of room.

Chris
