如何设计用户、产品和子产品的数据库架构?
该系统将有两种类型的用户。管理员和普通用户。管理员只能访问产品。如果管理员有权访问产品 A,则意味着他也有权访问其所有子产品。
普通用户只能访问子产品(一个或多个)。
添加管理员用户的屏幕将有一个产品下拉菜单,而添加用户的屏幕将有一个子产品下拉菜单。
产品管理员将添加产品子用户。
管理员用户和普通用户都将有一个表,因为这两个用户的其他所有内容都是相同的。
请帮忙。
The system will two types of users. Admins and normal users. Admins can have access to products only. If an admin have access to a product A, it means he also has access to all its sub products.
Normal users can have access to only sub products (one or more).
Screen to add Admin users will have a drop down of products while screen to add users will have a drop down of sub products.
Product Admin will add product sub users.
There is going to be a single table for both Admin users and Normal users as everything else is same for both users.
Please help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您基本上会看到这个:
Product
将在ParentId
上有一个自引用。如果它不是子类别,则ParentId
应为NULL
。您希望任何未定义“Admin”
的SystemRole
的人都无法访问任何具有Product
>NULLParentId
。UserRole
是一个关联表,提供M:N
SystemUser
与SystemRole
的关系。即使每个用户都有一个角色,现在最好以这种方式设置结构,这样您的应用程序将来更容易扩展。You're basically looking at this:
Product
will have a self-reference onParentId
. If it's not a sub-category thenParentId
should beNULL
. You'll want anyone who doesn't have aSystemRole
of"Admin"
defined to be unable to access anyProduct
that has aNULL
ParentId
.UserRole
is an association table that provides theM:N
relationship ofSystemUser
toSystemRole
. Even if each user will have a single role it's a good idea to set up the structure this way for now so your application is easier to expand in the future.