Rails has a has_one :through
association that helps set up a one-to-one association with a third model by going through a second model. What is the real use of
Inverse association: consider the classic situation user-membership-group. If a user can be a member in many groups, then a group has many members or users, and a user has many groups. But if the user can only be a member in one group, the group still has many members: class User has_one :group, :through => :membership
but class Group has_many :members, :through => memberships
. The intermediate model membership
is useful to keep track of the inverse relationship.
Expandability: a has_one :through
relationship can easy be expanded and extended to a has_many :through
relationship