Reputation: 40643
I need to develop an application that supports "schedules". Example of schedules:
If you have seen Outlook's scheduler, that's basically what I need. Here's a screen shot of their UI: http://www.question-defense.com/wp-content/uploads/2009/04/outlook-meeting-recurrance-settings.gif
How would I model such information in a database? Keep in mind that I also need to query this, such as:
I'm using PHP/MySQL, but am open to alternative solutions. Suggestions?
Upvotes: 4
Views: 1270
Reputation: 2230
My personal opinion is to create all the events separately, with a start and end date. Then generate a unique identifier for the event (perhaps the event ID of the first you create) and assign it to all events (so you know they are somehow linked).
Advantages:
Disadvantages:
-- appended from here --
Proposed Model:
id
big int (auto increment)ref_id
big int (this is kind of foreign key to the id)date_start
datedate_end
datetitle
stringsaved_recurrence
textImagine you have an event repeating 4 weeks every Wednesday and Friday:
ref_id
=0 and saved_recurrence
=saved JSON object and get the id that was used (auto incremented)ref_id
=idref_id
(saved_recurrence
can be empty here)You should now have 8 events (2 every week for 4 weeks) that have the same ref_id
. This way it's easy to fetch events in any date interval. When you need to edit an event, you just check for ref_id
. If it's 0 it's a single isolated event. If not, you have a ref_id that you can search to get all event instances.
Upvotes: 3