title: PG::UndefinedTable: ERROR: missing FROM-clause entry for table when using joins and where
body: <p>I have two models, <code>Courier</code> and <code>Order</code>. </p>
  
  <p>I have the following query below:</p>
  
  <pre><code>active_couriers = Courier.
    available_courier_status.
    where(:service_region_id =&gt; @service_region.id).
    includes(:orders)
  </code></pre>
  
  <p>This query works, however, it pulls in all orders. I want to limit the orders to only orders for the day. So I added the following query <code>where("orders.created_at &gt;= ?", Time.zone.now.beginning_of_day)</code>.</p>
  
  <pre><code>active_couriers = Courier.
    available_courier_status.
    where(:service_region_id =&gt; @service_region.id).
    includes(:current_orders).
    includes(:orders).
    where("orders.created_at &gt;= ?", Time.zone.now.beginning_of_day)
  </code></pre>
  
  <p>This give me the error:</p>
  
  <pre><code>PG::UndefinedTable: ERROR:  missing FROM-clause entry for table "orders"
  </code></pre>
  
  <p>What am I doing incorrectly here?</p>