gpt4 book ai didi

php - 如何根据父表自动更新子表中的列值?

转载 作者:行者123 更新时间:2023-12-04 04:09:11 27 4
gpt4 key购买 nike

My web app architecture for user access separated in two ways:- Manager Table (column: privilege) Employee Table (column: privilege, permission)

Where Manager is a Super-Admin account which will be used to subscribe our service based on package type(eg: basic, silver, gold).

For Employee, this acc will be created by Manager and share the same privilege of Manager by default(the subscribed service package). However, the Manager will need to set a permission level for each function in order for the Employee to be able to access the function in the web app.

The idea is, if session by manager acc, no permission needed. if session by employee, permission needed.

问题:当 Child 表中的新行创建时,'privilege' 列的默认值应遵循与 Parent 相同的值。此外,如果父级降级权限,子列值也应随之降级。

有没有办法从数据库的角度实现这一目标?我正在使用 postgresql。我知道这绝对可以从后端实现,但是每个 CRUD 操作都需要做很多逻辑。

最佳答案

您可以尝试使用触发器或存储过程并将逻辑放在数据库中。

关于php - 如何根据父表自动更新子表中的列值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62043396/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com