Mutuelinvestor
Mutuelinvestor

Reputation: 3538

How would you use a regular expression in an activerecord scope

I hoping to use a regular expression in a scope.

scope :smith, where(:full_name => /(smith)/) #names that include the word smith

Is this possible I've been trying different approaches to this and searched this site and others but to date I've been getting a variety of errors.

Note: :full_name is a database field.

Upvotes: 0

Views: 386

Answers (1)

Doon
Doon

Reputation: 20232

if using postgresql you can do this:

 scope :smith, where('full_name ~ ?', 'smith') 

sqlite you can see here http://titusd.co.uk/2010/01/31/regular-expressions-in-sqlite/ for something that might work. Have never tried it though.

Upvotes: 1

Related Questions