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 9254485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:28:53+00:00 2026-06-18T11:28:53+00:00

I have a table Schedules where I can store the day(s) a Person work.

  • 0

I have a table Schedules where I can store the day(s) a Person work. Now I want to add the hours this Person works. Let’s say Person works Monday from 9am to 11am, Tuesday from 9am to 6pm, and so on…

Also in every date range (from start_time to end_time ) how can I set the hours Person do not work like lunch time?

  create_table "schedules", :force => true do |t|
    t.datetime "created_at", :null => false
    t.datetime "updated_at", :null => false
    t.integer  "person_id"
    t.boolean  "sun"
    t.boolean  "mon"
    t.boolean  "tue"
    t.boolean  "wed"
    t.boolean  "thu"
    t.boolean  "fri"
    t.boolean  "sat"
  end  

Should I create a second table to store the hours of each day?

  • 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-18T11:28:54+00:00Added an answer on June 18, 2026 at 11:28 am

    I think modeling a Person’s work schedule will work better as a one-to-many:

    Person
      has_many :shifts
    end
    
    Shift
      #fields person_id, day, start_time, end_time
      belongs_to :person
    end
    

    Then, to create the schedule you describe (‘Monday from 9am to 11am, Tuesday from 9am to 6pm, and so on…’):

    @person = Person.find(1)
    @person.shifts.create!(:day => 'mon', :start_time => '9 am', :end_time => '11 am')
    @person.shifts.create!(:day => 'tue', :start_time => '9 am', :end_time => '6 pm')
    

    When you wanted to display this info, just iterate over the Person’s Shifts:

    @person.shifts.each do |s|
     puts "#{@person.name} works on #{s.day} from #{s.start_time} to #{s.end_time}."
    end
    

    You could choose to simply model ‘lunch breaks’ by giving the Person two shifts for that day . If, for instance, they worked from 9am to 7pm with an hour off starting at 1pm, give them on shift on that day from 9am to 1pm and one from 2pm to 7pm.

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

Sidebar

Related Questions

I have a SQL table containing train schedules. The table looks something like this:
I have a scheduled_item table where I can schedule animations to be displayed. Once
I have 2 tables, let says the first table named Schedule and the second
I have table and this table contain result column with some entries. I just
I have table with 300 000 records (MyISAM). I get record from this table
I have a table that looks something like this (simplified): *ScheduledReports* ReportID StartDate Frequency
I have a table called scheduler_sched which has several columns, including a column called
I have two tables: a schedule table that contains information about how an employee
I have a schedule grid based on a HTML table using jQuery/jQuery UI drag
I have table with around 70 000 rows. There is 6000 rows that i

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.