Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7824909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:45:35+00:00 2026-06-02T08:45:35+00:00

I’m developing a Rails 3 application (with MySQL as RDMS) to manage availability/occupancy for

  • 0

I’m developing a Rails 3 application (with MySQL as RDMS) to manage availability/occupancy for some Rooms (it’s an hotel-like app)
In my case, the problem is I’ve to keep up in the system 2 different requirements because one room can be rented for:

  1. Some months (for example 6 monts)
  2. Some days/weeks/weekend

Clearly the app has to show for each room in a given date, if it is available or not, and which user is renting; and on the other side, one user can search one room for a given date range.
The date range can be some fixed date or some months range (from September to March for instance) and I know this is something not related with the DataBase deisgn but I’ve to keep in mind.

To get this system working in a efficient way, I thought to create a table YEAR composite by a reference to the Room and an array (representing 1 year) of 365 elements when each element could be 0 or 1, when 0 means available and 1 means rented.

Adopting this solution I’ll have to face with some problems:

  1. Return very quick results when an user is searching for a room during some months.
  2. Managing ‘cross-years’ranges (for instance, from 20th of December of 2012 to 13rd of January of 2013)
  3. Leap years

and the last thing, I’m tying to avoid SQL procedure or mid-night processes (if it’s possible)

I’m sure there are better ways to design this problem in SQL…
Could some of you help me? or giving me some hint?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T08:45:37+00:00Added an answer on June 2, 2026 at 8:45 am

    Keep a list of room reservations which have a starting date and ending date. Don’t try to model availability slots or think of your reservation database like a spreadsheet. This will just lead you to pointless complexity. Date ranges are easy to work with.

    The most important thing to know is how to detect overlapping date ranges in your queries. This is the basis for testing whether a room is already reserved or whether it is free. Let’s say you have a RESERVATION table and you want to find reservations that overlap a given date range: @FromDate and @ToDate. Your WHERE clause for finding overlapping reservations looks like this:

    WHERE RESERVATION.start_date < @ToDate 
      AND RESERVATION.end_date > @FromDate
    

    Available rooms won’t have conflicts (i.e. WHERE NOT IN…) and unavailable rooms will have a conflict.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
We're building an app, our first using Rails 3, and we're having to build
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string
I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:
I would like to run a str_replace or preg_replace which looks for certain words

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.