STI question

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

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 K. [email protected]