From: Todd Benson Date: 2007-12-17T07:16:24+09:00 Subject: Re: teams -> members -> users On Dec 16, 2007 1:45 PM, John Griffiths wrote: > thanks, sort of works. > > isn't it possible to do: > > has_one :member > has_one :team, :through => member > > every time i try i get... > > undefined key(s) through Well, if your model is what I think it is, a team doesn't have one member. A user doesn't have one member either. Both a team and a user have zero or more "memberships". You can restrict the membershipness to exactly one for the user in the database if you want to with check constraints. (or you could just have 2 tables, team and member). How is this multiple<->multiple handled in Rails? I think it's handled like this (using ActiveRecord with the necessary table names and primary key names, of course): class Person < ActiveRecord::Base has_many :members has_many :teams, :through => :members end class Member < ActiveRecord::Base has_one :person has_one :team end class Team < ActiveRecord::Base has_many :members has_many :persons, :through => :members end not tested, Todd