Read more

Find records with a Range condition

Henning Koch
March 15, 2011Software engineer at makandra GmbH

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

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

Do you need DevOps-experts?

Your development team has a full backlog? No time for infrastructure architecture? Our DevOps team is ready to support you!

  • We build reliable cloud solutions with Infrastructure as code
  • We are experts in security, Linux and databases
  • We support your dev team to perform
Read more Show archive.org snapshot

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.

Posted by Henning Koch to makandra dev (2011-03-15 14:23)