title: Rails LEFT OUTER JOIN with Subquery
body: <p>I have a simple calendar application.</p>
  
  <p>Models:</p>
  
  <pre><code>class Day &lt; ActiveRecord::Base
    self.primary_key = "sdate"
    has_many :items, foreign_key: :sdate
  end
  
  class Item &lt; ActiveRecord::Base
    belongs_to :day, :foreign_key =&gt; :sdate
    belongs_to :calendar
  end
  
  class Calendar &lt; ActiveRecord::Base
    has_many :items
  end
  </code></pre>
  
  <p>Requirements:
  Fetch ALL rows of days within a certain date range.
  Fetch associated rows of items with certain Calendar-IDs.</p>
  
  <p>With SQL I could use the following query:</p>
  
  <pre><code>SELECT * FROM days LEFT OUTER JOIN (
    SELECT * FROM items
    WHERE calendar_id IN (1, 4)
  ) AS items
  ON days.sdate = items.sdate
  WHERE days.sdate BETWEEN '2015-03-01' AND '2015-03-31';
  </code></pre>
  
  <p>I have tried several ways in Rails but I couldn't find a solution.</p>
  
  <p>How can I do this in Rails 4? Eager loading would be great.</p>