如何设计用户、产品和子产品的数据库架构?

发布于 2025-01-02 20:38:40 字数 230 浏览 0 评论 0原文

该系统将有两种类型的用户。管理员和普通用户。管理员只能访问产品。如果管理员有权访问产品 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

宫墨修音 2025-01-09 20:38:40

您基本上会看到这个:

SystemUser: Id, AccountName
SystemRole: Id, RoleName
UserRole: SystemUserId, SystemRoleId
Product: Id, ParentId, Name

Product 将在 ParentId 上有一个自引用。如果它不是子类别,则 ParentId 应为 NULL。您希望任何未定义 “Admin”SystemRole 的人都无法访问任何具有 Product >NULL ParentId

UserRole 是一个关联表,提供M:N SystemUserSystemRole 的关系。即使每个用户都有一个角色,现在最好以这种方式设置结构,这样您的应用程序将来更容易扩展。

You're basically looking at this:

SystemUser: Id, AccountName
SystemRole: Id, RoleName
UserRole: SystemUserId, SystemRoleId
Product: Id, ParentId, Name

Product will have a self-reference on ParentId. If it's not a sub-category then ParentId should be NULL. You'll want anyone who doesn't have a SystemRole of "Admin" defined to be unable to access any Product that has a NULL ParentId.

UserRole is an association table that provides the M:N relationship of SystemUser to SystemRole. 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文