I’m using mysql and I’m working on the schema for a website I’m making. I’m a little stuck because I have users, communities (group of users), activities (plans made by either a user or a community that have one or more users or communities attending), and rsvps (containing the date a user/community rsvped to an activity). I’ve created a table for users, communities, and activities, but I’m stuck on rsvps:
The problem I’m having is that ideally I’d have something like this for the rsvps table:
USER/COM ID ACT_ID DATE Goin? U 2342 1 7/1/12 true U 1342 1 7/2/12 false U 2842 1 7/1/12 true C 5342 1 7/1/12 false
ID being a foreign key constraint to either the user or community tables depending on the value of the USER/COM attribute. Now I’m pretty sure it’s not possible to do it like this, so I’m just wondering how you would go about this.
Last note: I will have several other tables that will need to be able to use either users or communities together besides just the rsvp table, so I’d prefer for the idea to be as simple as possible for the rsvp table.
Please let me know if you need more info,
Thanks 🙂
I would make another table that connects users and communities.
This could be useful because users and communities might have similar types of information. As an example, users have a name (username), communities too. They might also have a register date, avatar and so on.. So you could have a table having for instance these columns: id, user_or_community_id, is_user, name, date_registred for example. Then all data thats specific to a user would be stored in the user table and same for the communities.
But I’m not sure, It’s a good question. This might get a bit complicated.