title: Querying on nested attribute
body: <p>I have a set of stores, that again have <code>locations</code>. These locations have different <code>business_hours</code>. The way I store the business hours are:</p>
  
  <pre><code> create_table "business_hours", force: :cascade do |t|
      t.time     "open_at"
      t.time     "close_at"
      t.integer  "week_day",    default: 0, null: false
      t.integer  "location_id"
      t.datetime "created_at",              null: false
      t.datetime "updated_at",              null: false
      t.index ["location_id"], name: "index_business_hours_on_location_id", using: :btree
    end
  </code></pre>
  
  <p>so I have a time on <code>open_at</code> and at <code>close_at</code>. What I'd like to get from the store, is the locations that are available at the time that I query.</p>
  
  <p>So for example today is Wednesday, and my local time is 12:40. I want it to return all the locations that are open on Wednesday at 12:40.</p>
  
  <p>I've started writing a method but unsure how to complete it.</p>
  
  <pre><code>def locations_open(local_time: Time.zone.now.in_time_zone('Stockholm'))
   current_day = local_time.wday
   store.locations.join(:business_hours).where(business_hours: { week_day: current_day })
   # and current time is open_at &lt;&gt; close_at
  end
  </code></pre>