STI include in find

Hi,

I am using single table inheritance in my application as follows:

class Company < ActiveRecord::Base
...
end

class Member < Company
...
end

class Applicant < Company
...
end

class Application < ActiveRecord::Base
  has_one :applicant
  has_one :member
...
end

I wish to use an include statement when I do a find on the Application
(ie. Application.find(:all, :include => [:member]). Is there a way to
accomplish this. I'm assuming it is not working because of the STI.

Thanks for your help.

Hey Lundie,

That’s odd…this sounded weird to me so I setup a sample app and tested it. It works as expected (note the 2 mysql calls the find generates, as you would expect):

ActiveRecord#explain is added by the (very young) explain-query gem

Post.explain do
?> Post.find :first, :include => [:user]

end
SELECT * FROM posts LIMIT 1
select_type | key_len | table | id | possible_keys | type | Extra | rows | ref | key