From what you''re describing it sounds like you might be better with a
single User model, with guest as a role, rather than separate models.
In that way Message would have_one wrter
:class_name=>''User''.
On Feb 11, 12:49 pm, Sam Kong
<rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:> Hi,
>
> I am learning Single Table Inheritance and have a question.
>
> In my application, a message may be written by a user or by a guest.
> Thus a writer of a message is virtually associated either to a user or a
> guest.
>
> class Message < ActiveRecord::Base
> end
>
> class UserMessage < Message
> belongs_to :writer, :class_name => ''User''
> end
>
> class GuestMessage < Message
> belongs_to :writer, :class_name => ''Guest''
> end
>
> When I retrieve a list of messages, I want to include writer association
> for performance.
>
> messages = Message.find :all, :include => [:writer] # This
doesn''t work.
>
> How can I make the above code work?
> If not, is there an workaround?
>
> Thanks.
> Sam
> --
> Posted viahttp://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---