加入相同的 Rails 模型两次,例如,人们通过会员资格拥有许多俱乐部,人们通过委员会拥有许多俱乐部

发布于 2024-09-04 08:28:54 字数 340 浏览 2 评论 0原文

型号: * 人 * 俱乐部

关系 * 会员资格 * 委员会

人员应该能够加入俱乐部(会员资格) 人们应该能够成为俱乐部(委员会)的董事会成员,

对于我的应用程序,这些涉及截然不同的功能,因此我宁愿不使用标志来设置(is_board_member)或类似的标志。

我发现自己想写:

人 has_many :clubs :through => :会员资格 # :as => :成员? :foreign_key => : 会员 ID? has_many :clubs :through => :委员会#如(上面)

但我不太确定如何将其拼接在一起

Models:
* Person
* Club

Relationships
* Membership
* Committee

People should be able to join a club (Membership)
People should be able to be on the board of a club (Committee)

For my application these involve vastly different features, so I would prefer not to use a flag to set (is_board_member) or similar.

I find myself wanting to write:

People
has_many :clubs :through => :membership # :as => :member? :foreign_key => :member_id?
has_many :clubs :through => :committee # as (above)

but I'm not really sure how to stitch this together

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

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

发布评论

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

评论(1

轮廓§ 2024-09-11 08:28:54

尝试

has_many :committee_clubs, :through => :committee, :source => :clubs
has_many :membership_clubs, :through => :membership, :source => :clubs

Try

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