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

  • Home
  • SEARCH
  • 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 935275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:07:53+00:00 2026-05-15T21:07:53+00:00

I’m looking at making a booking system and I need to display all the

  • 0

I’m looking at making a booking system and I need to display all the available users on a particular day/time.

Thinking about it, I’m going to set up a table to keep note of when people AREN’T available, and assume that they are otherwise available. The structure I had in mind was to keep a note of the date_start of when they won’t be available, and then the date_end.

Now the problem arises when I’m trying to book a meeting, if I want to book something on Tuesday for 11:00 until 13:00 I need to fetch a list of those people that are available then, i.e. don’t have any holidays booked at during that time.

Any ideas or thoughts? I’ll be using Ruby on Rails if that helps/hinders anyone’s ideas.

  • 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-05-15T21:07:53+00:00Added an answer on May 15, 2026 at 9:07 pm

    Here’s one way to model it. Lets say we have a model ‘Engagement’ which has a start datetime, end datetime and name. An engagement has many users, through another join table called ‘user_engagements’ (with corresponding UserEngagement model). So we have

    User
      has_many :user_engagements
      has_many :engagements, :through => :user_engagements
    
    Engagement
      #fields - starts_at, ends_at (both datetime)
      has_many :user_engagements
      has_many :users, :through => :user_engagements
    
    UserEngagement
      belongs_to :user
      belongs_to :engagement
    

    Now we have a nice simple schema. An engagement basically models something that’s happening, and user_engagements model users who are booked to do that thing. We have an assumption (not written into the code) that when they are doing something they aren’t available to do anything else.

    Our next task is to write a method that returns users available within a given time period, ie a new engagement. So, we make an engagement and we want all the users who don’t have an engagement which crosses over with our new engagement. I think the simplest way of doing this might be to find all the users who do have a crossing-over engagement and then return all the users who aren’t them. If you know what i mean. A more precise way of saying e2 crosses over with e1 is that e2 starts before the end of e1 AND ends after the start of e1.

    Let’s make this a method of an engagement object since it’s totally dependent on an engagement’s data.

    #in Engagement
    def unavailable_user_ids
      User.find(:all, :include => [:user_engagements], :select => "users.id", :conditions => ["user_engagements.starts_at < ? and user_engagements.ends_at > ?", self.ends_at, self.starts_at]).collect(&:id)
    end
    
    def available_users
      User.find(:all, :conditions => ["id not in (?)", self.unavailable_user_ids])
    end
    

    I feel like there’s a more efficient way to get this in one query but i can’t quite put my finger on the sql.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
In my XML file chapters tag has more chapter tag.i need to display chapters
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I am reading a book about Javascript and jQuery and using one of the
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I have a text area in my form which accepts all possible characters from
i want to parse a xhtml file and display in UITableView. what is the

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.