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