Rails 与第三方关系中定义的多个角色
我正在构建一个小型应用程序,其中包含用户、学生、导师、会议类。
每个用户可以在一个会议中担任导师,但在另一次会议中可以担任学生。我一直在思考如何建模这些关系。
现在,我有一个用户模型,一个单独的参与者模型,其属性 Role =“tutor”/“student”。 Tutor和Student使用单表继承来扩展Participant,并且属于Meeting。
不过,我想知道这是否是一个好的设计。 (这对我来说似乎不直观)。
如果你遇到我的情况你会怎么做?
谢谢。
I am building a small app which has classes User, Student, Tutor, Meeting.
Each user can be tutor in one Meeting, but student in another meeting. I have been thinking about how to model these relationship.
Right now, I have a User model, a separate Participant model with an attribute Role = "tutor"/"student". Tutor and Student extend Participant using single-table inheritance, and belong to Meeting.
However, I wonder if this is a good design. (It seems to be unintuitive to me).
What would you do in my situation?
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是可以接受的,但还有其他更干净的方法。您可以像这样设计您的
Meeting
模型:您的
User
模型:因此您只需要两个模型。
// 编辑
对于提议、接受、拒绝等,我将创建一个
Invitation
模型user_id:integer
(受邀用户)、meeting_id
(通过你知道谁可以邀请其他人,因为会议属于导师),status:string
(等待、接受、删除可能是选项)也许explaination:text
(当有人美味佳肴)。It is acceptable but there are other ways that are cleaner. You could design you
Meeting
model like this:Your
User
Model:So you would only need two models.
// edit
For propose, accept, decline,.. I would create a
Invitation
Modeluser_id:integer
(Invited User),meeting_id
(Through this you know who is allowed to invite other people because Meeting belongs to the tutor),status:string
(waiting, accepted, delicesed might be options) maybeexplaination:text
(When somebody delices).