I’m working on a goal completion application, where there can be Goals, Milestones, and Tasks. Milestones belong to goals, goals can have many milestones, and tasks can belong to either goals, milestones, or stand on their own. The information I want to store in each model is as follows:
Goal content:string, est_completion_date:date completed:boolean, completion_date:date
Milestone content:string, est_completion_date:date completed:boolean, completion_date:date
Task content:string, occur_on:date completed:boolean, completion_date:date, days:?
The ‘occur_on’ field for the Task model is to schedule the task for a custom date. The ‘days’ field stores what days of the week the task should happen, if it’s recurring.
I have two questions.
1) I read about single table inheritance and wondered if this would work for me. Every model is pretty much the same except the Task model has ‘days’ and ‘occur_on’, but doesn’t have ‘est_completion_date’. What’s the best way to model all of these associations?
2) I’m not quite sure how to best store the information regarding what days of the week a task should occur on. Should I just make it an associative array with boolean values for each day, or should I have separate fields for each day in the table?
1) Your single table inheritance question is well answered here.
2) I recommend keeping it simple for your
dayscolumn. Just store a string of digits, with each digit representing a day. So245might represent Monday, Wednesday & Thursday. To find tasks that occur on Wednesday you can query with a regular expression, e.g.select * from tasks where days regexp("4");