Find records with a Range condition

Updated . Posted . Visible to the public.

You can find ActiveRecord models by using a Range Show archive.org snapshot as its conditions:

User.scoped(:conditions => { :id => 3..5 })

This will generate the following query:

SELECT * FROM `users` WHERE (`users`.`id` BETWEEN 3 AND 5)

This also means that all your scopes that take an array of allowed values and use condition hashes, automagically work for Ranges, too.

Henning Koch
Last edit
Keywords
activerecord
License
Source code in this card is licensed under the MIT License.
Posted by Henning Koch to makandra dev (2011-03-15 13:23)