I'm a Ruby noob, and I'm pretty convinced there's an elegant way to implement what I'm trying to do. I thought I'd ask if there's any idioms I could use.
Two classes: "team" and "member" joined in a team_members table. In addition to the IDs, the team_members group has a "permissions" column. The permission can take three values: creator, participant or observer.
The Member model has three collections: created_teams, , participating_teams, and observed_teams. I use the following construction (this is only the observers collection, but it's the same for the other two.)
has_many :member_teams has_many :observed_teams, :through => :member_teams, :source => :teams, :conditions => "member_teams.permissions = '#{Observer}'
Works like a charm and I love it. Here's my question.
I'd like to set the permissions field on the member_teams table when I assign it to a collection. For example,
t = Team.new member.participating_teams << t
That does insert a record in the join table, but I have to access the join record manually and set the permission, otherwise it's null. I'd like it to be set to "participant" in the instance above, or "observer" if added to the observed_teams collection, etc.
Is there a Ruby Way?