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

On Mar 11, 10:15 am, David Beckwith <[email protected]> wrote:
> And it would be cool to be able to say:
>
> @user.student # if the role was present or give nil otherwise.
>
> On Mar 12, 12:11 am, David Beckwith <[email protected]> wrote:
>
> > 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.
>
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to