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?
I think modeling a Person’s work schedule will work better as a one-to-many:
Then, to create the schedule you describe (‘Monday from 9am to 11am, Tuesday from 9am to 6pm, and so on…’):
When you wanted to display this info, just iterate over the Person’s Shifts:
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.