开发者

join same rails models twice, eg people has_many clubs through membership AND people has_many clubs through committee

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 开发者_JAVA百科sure how to stitch this together


Try

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜