# Reservations and Availability

**URL:** <https://www.ruby-forum.com/t/reservations-and-availability/125933>\
**Category:** Rails\
**Created:** [January 13, 2008, 11:36pm UTC](https://www.ruby-forum.com/t/reservations-and-availability/125933 "2008-01-13T23:36:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeremy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/82dd89/32.png) [@jeremy](https://www.ruby-forum.com/u/jeremy)\
**Post date:** [January 13, 2008, 11:36pm UTC](https://www.ruby-forum.com/t/reservations-and-availability/125933/1 "2008-01-13T23:36:09Z")

</div>

Hello…this amounts more to SQL questions rather than Rails specific  
I guess. I’m new to both.

Basically what I’m trying to do is perform a search for sites which  
are available for a reservations system. I have a Sites model and I  
have a Reservations model. Reservations contains columns for  
checkindate and checkout date. I also created a model for Booking  
status, which has columns for site\_id and date to show which dates and  
which sites are booked, but I’m not even sure I necessarily need this  
table if there’s a way to query just using the Sites and Reservations  
models.

The parameters I want to use at this point for the query is to let the  
user choose a checkindate and a checkout date and I want to return a  
list of sites which are available.

Any help?

---

<div class="post-metadata">

**Author:** ![jeremy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/82dd89/32.png) [@jeremy](https://www.ruby-forum.com/u/jeremy)\
**Post date:** [January 14, 2008, 8:14am UTC](https://www.ruby-forum.com/t/reservations-and-availability/125933/2 "2008-01-14T08:14:48Z")

</div>

On 13 Jan 2008, at 22:35, Jeremy wrote:

> table if there’s a way to query just using the Sites and Reservations  
> models.
> 
> The parameters I want to use at this point for the query is to let the  
> user choose a checkindate and a checkout date and I want to return a  
> list of sites which are available.

I’ve done something slightly different, where there was only one site,  
but that site could have multiple reservations for any given date (and  
with a varying number of available places on any given day).  
Effectively, what i did was have an availabilities table, where each  
row states that the site in question is available on the given time  
segment (in your case, a single day).  
You can then say ‘give me the sites which have availabilities in the  
given date range’ and then check that the sites returned have all of  
those availabilities, not just some of them (you may be able to roll  
that all into one query.

Fred
