Skip to content
This repository has been archived by the owner on Mar 30, 2022. It is now read-only.

Tips and tricks

ernie edited this page Apr 11, 2012 · 6 revisions

Squeel Tips and Tricks

Have a handy pattern you've adopted that showcases how Squeel can make your code more readable, or allow you to do things that you couldn't easily do with SQL strings? Put it here. To start things off, a sample from the README.

Arbitrary-length ORed conditions against a single column

In standard ActiveRecord, to handle an arbitrary list of potential matches on a single database column, you might do:

Person.where((['name LIKE ?'] * names.size).join(' OR '), *names)

With Squeel, you can use the *_any predicates:

Person.where{name.like_any names}
Clone this wiki locally