title: Rails 3 eager loading of deep nested association
body: <p>I am building a public activity stream which contains a stream of the following:</p>
  
  <ol>
  <li>User posted 3 minutes ago</li>
  <li>User starred a post</li>
  </ol>
  
  <p>I am using the <a href="https://github.com/pokonski/public_activity">public_activity</a> gem for achieving this.</p>
  
  <p>My question is whether there is a way to use the <code>includes</code> for a polymorpic function.</p>
  
  <p>The code that i am running currently is as follows:</p>
  
  <pre><code>#app/models/post.rb
  
  class Post &lt; ActiveRecord::Base
  
      include PublicActivity::Common
  
      attr_accessible :content, :visibility
  
      validates_presence_of :content
  
      belongs_to :postable, :polymorphic =&gt; true
      has_many     :stars
  
  end
  
  #app/models/star.rb
  class Star &lt; ActiveRecord::Base
  
    include PublicActivity::Common
  
    validate :duplicate_star
  
        belongs_to :user
    belongs_to :post
  
  private
      def duplicate_star
   errors.add(:base, "Post already starred") if Star.exists?(:user_id =&gt; self.user, :post_id =&gt; self.post)
     end
  
  end
  
  
  #app/controllers/users_controller.rb
  class UsersController &lt; ApplicationController
    def index
      @post = Post.new
      @activities = PublicActivity::Activity.order("id desc").all.includes(:trackable, :owner)
    end
  end
  </code></pre>
  
  <p>The trackable can be a post or a star.
  I have render functions for displaying both.
  The problem is, if I try to output something like {user} starred {postcontent}, it does it this way:</p>
  
  <pre><code>activity.trackable.post.content
  </code></pre>
  
  <p>So this results in multiple queries, each time it finds a post.
  How do I tackle this problem/situation?</p>
  
  <p>Thanks in advance.</p>