tags:

views:

61

answers:

1

I'm making an online calendar.

One will be able to create en event and then have the possibility to choose to add "infinite" or "from" to "end" datetime. And if you choose to add a "from" to "end" you can choose it to be no repeat or repeat every day, every week or every month.

I wonder what is the best way to create these relations.

Here are my tables I'm having right now:

Table: Events
Columns: name, description, date_time (foreign key)

Table: Date_time
Columns: from, to, repeat (foreign key)

Table: Repeat
Columns: mode, days
1: "daily", "every 2nd day"
2: "weekly", "Monday, Wednesday"
3: "monthly", "1st, 12th, 19th"

With this I encounter some problems.

Here I have to specify an Events.date_time because it's having a foreign key constraint. How can I let the user choose to not specify any datetime, just have it set to infinite.

And the same goes for Repeat. If the user has set a datetime I want to give the possibility to set the repeat to none.

Could someone point me into right direction.

Thanks

+2  A: 

I would suggest to reconsider the schema, my proposal is such:

EDIT: since Event may have not more than one Period, it is better to use from and to as columns, if they are null then event is valid infinitely.

Table: Events
Columns: id, name, description, from (nullable), to (nullable)

Table: Repeat
Columns: mode, days, event_id (foreign key to Event)
1: "daily", "every 2nd day"
2: "weekly", "Monday, Wednesday"
3: "monthly", "1st, 12th, 19th"
Tim