This is a slightly complicated setup but please bear with.
Basically I am creating a 'dress up' game. A user has many clothes and clothes can be assigned to many users so I have created (I think you call it) a pivot table user_clothes to represent this.
But clothes have a type for example 'dress', 'shoes' etc. I only want a user to be able to have one item per layer and want the database to reject an attempt to bypass this. Is there a way I can create a unique combined key on user_clothes that only allows one item per layer based on my database architecture?
I have four tables: users, user_clothes, clothes, clothes_type
users
- id (PK)
clothes_type
- id (PK)
clothes
- id (PK)
- clothes_type_id (FK: clothes_type.id)
user_clothes
- id (PK)
- user_id (FK: user.id)
- clothes_id (FK: clothes.id)