How do you eager load polymorphic has_many :through
associations in Rails/ActiveRecord?
Here's the base setup:
class Post < ActiveRecord::Base
has_many :categorizations, :as => :categorizable
has_many :categories, :through => :categorizations
end
class Category < ActiveRecord::Base
has_many :categorizations, :as => :category
has_many :categorizables, :through => :categorizations
end
class Categorization < ActiveRecord::Base
belongs_to :category, :polymorphic => true
belongs_to :categorizable, :polymorphic => true
end
Assuming that we want to solve this eager loading problem for Rails 2.3.x and double polymorphic associations on the join model, how do you eager load the :through
association on something like this:
posts = Post.all(:include => {:categories => :categorizations})
post.categories # no SQL call because they were eager loaded
That's not working, any ideas?