needing some help setting up some tables and their foreign key constraints.
3 total tables:
UserTable - contains:
- UserID
- Other Fields
ShapeTable - contains:
- ShapeID
- UserID (from UserTable)
- Other Fields
RecipientTable - contains:
- RecipientID
- UserID (from UserTable)
A user is able to draw a shape, or many shapes. A user can also add potentially many recipients. A shape can have 0 or many user's recipients added to it.
If a recipient is deleted by user, it should be removed from all stored shapes. If a shape is deleted by user, it should not delete recipients.
I'm struggling with how to design the "mappings" between the Shapes and the Recipients for each user.
When a user draws a shape, I want to present all the recipients for the user that drew the shape. The user will then be able to select 0, 1, or many of those recipients for that given shape. I'll need to be able to retrieve this later on as well. When a shape is deleted, I want it to delete the "mappings" to any recipients as well, but not necessarily delete the actual recipient record.
What is the best way to arrange the tables, should there be an additional "mappings" type table created, and what foreign key constraints should exist to enforce cascading and referential integrity?
Let me know if there's a better way to present the question if I left something out. I am using MySQL (InnoDB) and PHP (if that matters).