Database Design: One to many of different types

大城市里の小女人 提交于 2019-12-11 08:35:37

问题


The work flow for something is as follows

1) Create a "Message of the Day" for a particular group of users (which must be approved before active)

2) Assign who can approve this by selecting single users, and/or users who are admins of the group this MOTD is going into, or any other number of groupings for users.

3) "Message of the Day" must no be approved by one of the 'approvers' selected.

How can I relate a MOTD record, to one or more of "single users" and/or "groupings of users"


回答1:


One way is to add a type field to a mapping table. This works for many-to-many of different types.

create table motd_approvers (
  id int auto_increment primary key,
  motd_id int not null,
  user_id int not null,
  user_type enum('admin','user') not null
);

I don't think it's actually a one-to-many. You have many MOTD entries and many users who can be approvers for many MOTD entries.



来源:https://stackoverflow.com/questions/9900793/database-design-one-to-many-of-different-types

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!