views:

11

answers:

1

How can I translate this MySQL's WHERE to ActiveRecord :condition?

 SELECT * FROM users WHERE LENGTH(users.last_name) < 3

Thanks!

A: 
User.find(:all, :conditions => ["LENGTH(last_name) < ?", 3])

or you can use find_by_sql

 User.find_by_sql("SELECT * FROM users WHERE LENGTH(users.last_name) < 3")
Salil