# Data modeling a timesheet

**URL:** <https://www.ruby-forum.com/t/data-modeling-a-timesheet/111604>\
**Category:** Rails\
**Created:** [August 9, 2007, 1:53am UTC](https://www.ruby-forum.com/t/data-modeling-a-timesheet/111604 "2007-08-09T01:53:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![rubylover](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8c91f0/32.png) [@rubylover](https://www.ruby-forum.com/u/rubylover)\
**Post date:** [August 9, 2007, 1:53am UTC](https://www.ruby-forum.com/t/data-modeling-a-timesheet/111604/1 "2007-08-09T01:53:40Z")

</div>

I have an existing application that lets a company track the tutor/  
student relationships through a Job model. I now want to add in  
functionality that lets the tutors login and enter the time they spend  
each week tutoring for each of their respective jobs.

im building this functionality into a rails app, but im not sure if im  
modeling it in the best way.

For each active job there is a row that lists the client’s name as  
well as each day of the week (monday → Sunday) so the tutor can enter  
their hours, and minutes for that day.

I’m going to create a Timesheet model that stores the tutor\_id, year  
and week # (so I can just calculate the first day of week and iterate  
from there). The Timesheet model will have a has\_many relationship  
to an Activity model that has the timesheet\_id and job\_id.

Activity will then have a has\_many relationship to a Day model that  
will include the date, hour and minute fields for each day.

Im not sure if that is the right way to go about it though.

class Job  
belongs\_to :student, :tutor  
has\_many :timesheets  
end

class Timesheet  
belongs\_to :job  
has\_many :days  
end

class Day  
belongs\_to :timesheet  
end

Here’s a screenshot of my mockup for reference:

[http://carpeaqua.com/images/tsmock.png](http://carpeaqua.com/images/tsmock.png)

Any suggestions are appreciated.

Thanks!
