Has_many through polymorphic true


#1

This would be cool to have in Rails.

class User < ActiveRecord::Base
has_many :roles
end

class Role < ActiveRecord::Base
belongs_to :user
belongs_to :rolable, :polymorphic => true
end

class Student < ActiveRecord::Base
has_one :role, :as => :rolable
has_one :user, :through => :rolable # * This is not possible
yet in Rails (I think).
end

class Teacher < ActiveRecord::Base
has_one :role, :as => :rolable
has_one :user, :through => :rolable # * This is not possible
yet in Rails.
end

Then be able to say:

@student.user # Instead of having to say @student.role.user

Or even better be able to say @student.email when email was a column
of User but not Student.


#2

And it would be cool to be able to say:

@user.student # if the role was present or give nil otherwise.


#3

I believe that the @student.user case is possible, so long as you
change the :through => :rolable, to :through => :role