views:

98

answers:

2

I am creating a simple todo app where I have 2 types of tasks.

1) regular tasks - These have a due date 2) recurring tasks -These are poped up as reminders on specified date. They can be created either as weekly or monthly reminders. If created for a week, it will be poped up on each week (on a specified date on the week). Likewise for a month it need to be specified the week and the date.

What will be the best way to model this scenario?

+2  A: 

I would have two columns for the reminder object - remind_at (date) and repeat_frequency (something to identify different re-occurrences by). That way, you could index the remind_at column and search by it quite quickly. Each time a reminder is shown to user, it would look at repeat_frequency - if it contains directions for repeating, set remind_at to next date, if not, delete/archive the reminder.

Toms Mikoss
A: 

You could model a Task to have a due_date. But if a task is recurring, due_date will be null and you would use the recurrence field to compute the next_due_date. recurrence would be a string field holding a parsable string like "tuesday" (for weekly) or "17" (a day number for monthly).

def next_due_date
  if due_date
    due_date
  else
    # compute next due date using the 'recurrence' field and today's date
  end
end

This may or may not be the "best way" for you, depending on your requirements, and the future needs of the model.

Jonathan Julian