Quickest way to get first and last item in ActiveRecord date range query?
<p>I want to get the first and last items in a date range with ActiveRecord. I could </p>

<p><code>BalanceLedger.where(created_at: Time.now-7.days..Time.now).order(:created_at).first</code> </p>

<p>and </p>

<p><code>BalanceLedger.where(created_at: Time.now-7.days..Time.now).order(:created_at).last</code>  </p>

<p>to get the first and last in this weekly range but this seems like it will just return a lot with each query when I am just looking for 2 entries.</p>

<p>What is most efficient to get the first and last in this range?</p>