For some reason it seems that :include is not working for a couple of
my associations. Here are the models I’m using:
MODELS
class Registration < ActiveRecord::Base
has_many :events, :foreign_key => :user_id
end
Note the single table inheritance
class User < Registration
end
class Event < ActiveRecord::Base
belongs_to :user
has_one :image, :as => :imageable, :dependent => :destroy
end
class Image < ActiveRecord::Base
belongs_to :imageable, :polymorphic => true
end
I’m using single table inheritance with Registrations because there
are 2 types of users on the site: User and TmpUser. A TmpUser is
essentially a shell that should not have any validation when saved and
a different set of filters.
When I run the following code it does not load either the image or
user association in the query:
evts = Event.find(:all, :include => [:image, :user], :conditions =>
“start IS NOT NULL AND start >= CURDATE()”)
So it runs a new query for each of these statements:
evts.first.image
evts.first.user
What am I doing wrong?
Thanks,
Jeremy