This project is archived and is in readonly mode.

#255 ✓duplicate
Alex Arnell

activerecord condition hashes should respect ruby range syntax

Reported by Alex Arnell | May 26th, 2008 @ 05:00 PM

Ruby has some explicit rules for Ranges,

a = 1..10 => 1 through 10
b = 1...10 => 1 through 9

but activerecord doesn't follow those rules when uses condition hashes. Take for example:

date_range = (2.weeks.ago.to_date)...(Date.today)
Post.find(:all, :conditions => { :published_at => date_range })

When I read this could I would expect that query to return all the posts that happened in the last two weeks prior to today. However this is not the case. Activerecord uses the BETWEEN sql syntax to handle ranges, which means that the above query actually runs equivalently to (min <= published_at AND published_at <= max).

Attached is a patch (including tests) that corrects this behavior.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Attachments

Pages