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.