Rails 设计模式:一个分发列表类中的组和个人

发布于 2024-12-04 18:26:57 字数 257 浏览 3 评论 0原文

我有一个用户类,它有很多事件并且属于很多组。我想允许用户创建活动并通过组、用户 ID 或两者来限制他想要邀请的人。

我正在考虑创建一个表 Invitee 来存储所有用户的 id 和事件 id。对于每个事件,当用户 A 选择邀请组 Z 以及用户 B 和 C 时,我将查询组 Z 以查找成员的所有用户 id,并将它们与 B 和 C 的用户 id 一起添加到 Invitee 表中。

我认为这可能不是最好的方法。我想知道是否有更好的方法来做到这一点。

谢谢。

I have a class User, which has many Events and belongs to many Groups. I want to allow user to create Event and restrict who he wants the invite by Group, by user id or by both.

I am thinking creating a table Invitee to store all users' id and events id. For each Event, when user A chooses to invite group Z and users B and C, I will query group Z to find all user id of the members and add them to Invitee table, together with B and C's user id.

I think it is might not be the best way to do it. I wonder if there is a better way to do it.

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

迷乱花海 2024-12-11 18:26:57

查看多态关联:基本上您需要可以是任一实体类型的邀请。

Look in to polymorphic associations: basically you want invitations that can be either entity type.

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