title: How to use includes with 3 models w ActiveRecord?
body: <p>Given the following model:</p>
  
  <pre><code>Room (id, title, suggested)
    has_many :room_apps, :dependent =&gt; :destroy
  
  RoomApp (room_id, app_id, appable_id, appable_type)
    belongs_to :appable, :polymorphic =&gt; true
    has_many :colors, :as =&gt; :appable
    has_many :shirts, :as =&gt; :appable
  
  Colors (room_id)
    belongs_to :room
    belongs_to :room_app
    belongs_to :app
  </code></pre>
  
  <p>What I want to do is get all the suggested rooms. In my controller I have:</p>
  
  <pre><code>@suggested_rooms = Room.includes(:room_apps).find_all_by_suggested(true).first(5)
  </code></pre>
  
  <p>Problem here is the includes is not working and the db is being hit several times:</p>
  
  <pre><code>Processing by PagesController#splash as HTML
    Room Load (0.6ms)  SELECT "rooms".* FROM "rooms" WHERE "rooms"."suggested" = 't' ORDER BY last_activity_at DESC
    RoomApp Load (0.6ms)  SELECT "room_apps".* FROM "room_apps" WHERE "room_apps"."published" = 't' AND ("room_apps".room_id IN (5,4,3)) ORDER BY created_at DESC
    RoomApp Load (5.9ms)  SELECT "room_apps".* FROM "room_apps" WHERE "room_apps"."published" = 't' AND "room_apps"."id" = 6 AND ("room_apps".room_id = 5) ORDER BY created_at DESC LIMIT 1
    Color Load (0.4ms)  SELECT "colors".* FROM "colors" WHERE "colors"."id" = 5 LIMIT 1
    RoomApp Load (0.6ms)  SELECT "room_apps".* FROM "room_apps" WHERE "room_apps"."published" = 't' AND "room_apps"."id" = 5 AND ("room_apps".room_id = 4) ORDER BY created_at DESC LIMIT 1
    Color Load (0.4ms)  SELECT "colors".* FROM "colors" WHERE "colors"."id" = 4 LIMIT 1
    RoomApp Load (0.4ms)  SELECT "room_apps".* FROM "room_apps" WHERE "room_apps"."published" = 't' AND "room_apps"."id" = 4 AND ("room_apps".room_id = 3) ORDER BY created_at DESC LIMIT 1
    Color Load (0.3ms)  SELECT "colors".* FROM "colors" WHERE "colors"."id" = 3 LIMIT 1
  </code></pre>
  
  <p>Is something setup incorrectly? I'd like to be able to get suggested rooms and use includes for room_apps with one hit versus currently where it's a hit for every room.</p>
  
  <p>Ideas? Thanks</p>