My application has two models I’d like to have multiple join tables
between, Users and Groups. Users have the ability to subscribe to a
Group, while a Group would like to know its membership.
Additionally, a User can administer several Groups and a Group should
know about its several Administators (Users).
I have the following declarations:
class Administrator < ActiveRecord::Base
class GroupSubscription < ActiveRecord::Base
class Group < ActiveRecord::Base
has_many :users, :through => :group_subscriptions
has_many :users, :through => :administrators
class User < ActiveRecord::Base
has_many :groups, :through => :group_subscriptions
has_many :groups, :through => :administrators
In the database, I have Users, Groups, Group_Subscriptions, and
Administrators (admin holds a user_id, and group_id) tables.
Obviously, what seems to be happening is that the second :groups
declaration overrides the first, preventing me from finding the
groups that someone is subscribed to. It seems as if I should want
to provide a different name for the association while still
specifying that it should be between Users and Groups. In essence,
saying the following in User:
has_many :administrators has_many: groups_administered, :through => :administrators
However, this causes Active Record (I think) to no longer know what
it should be joining to with this particular association. Can anyone
provide some tips on how to overcome this?