views:

17

answers:

0

What is the correct way to model many has_one (or even has_many) relationships on a model where each has_one is just a different role/context of some class?

class Group < ActiveRecord::Base
  has_many :memberships, :as => :membered
  has_one :admin, :class_name => "User", :through => :memberships
  has_one :speaker, :class_name => "User", :through => :memberships
  has_one :contact, :class_name => "User", :through => :memberships
  has_many :members, :class_name => "User", :through => :memberships
end

class User < ActiveRecord::Base
  has_many :memberships, :as => :a_member
  has_many :user_roles
  has_many :roles, :through => :user_roles
end

class Membership < ActiveRecord::Base
  belongs_to :membered, :polymorphic => true
  belongs_to :a_member, :polymorphic => true
end

Without having to use STI or anything, what's the preferred way to accomplish something like this?