开发者

How to model the associations for a task application?

开发者 https://www.devze.com 2023-03-10 04:32 出处:网络
I\'m working on a goal completion application, where there can be开发者_JAVA百科 Goals, Milestones, and Tasks. Milestones belong to goals, goals can have many milestones, and tasks can belong to eithe

I'm working on a goal completion application, where there can be开发者_JAVA百科 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 days column. Just store a string of digits, with each digit representing a day. So 245 might 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");

0

精彩评论

暂无评论...
验证码 换一张
取 消