在这种情况下可以使用STI吗?
我有一个名为 people
的表 每个人
可以是客户
、经理
、会计师
或三者的任意组合。 除了 people
表中的列之外,它们每个都有特殊的表列。
我现在正在做的是在每个表中使用 person_id
...但我认为仅使用同一个表并为每个表使用不同的模型会更简单,所以我可以单独管理它们。
我应该这样做吗?
I have a table named people
Each person
can be a client
, a manager
, an accountant
, or any combination of the three.
Also each of them have special table columns, besides the ones in the people
table.
What I'm doing now is using a person_id
in each of the tables... but I think it would be much simpler to just used the same table, and a different model for each one, so I can manage them separately.
Should I do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你没有一个很好的继承层次结构,所以我认为 STI 不适用。例如,就(单一)继承而言,您如何代表既是经理又是会计师的人?
如果一个人只能扮演这三种角色中的一种,那么性传播感染也许是有意义的;但即便如此,使用继承来实现角色应该会在您的脑海中敲响警钟,您应该知道一个人迟早会需要多个角色(并且可能在交付后立即成为一种关键必需品)。
You don't have a nice inheritance hierarchy so I don't think STI applies. For example, how would you represent a person that was both a manager and an accountant in terms of (single) inheritance?
If a person could only have one of the three roles then maybe STI would make sense; but even then implementing roles using inheritance should be setting off warning bells in your head, you should know that one person will end up needing multiple roles sooner or later (and it will probably become a critical necessity immediately after delivery).