Case insensitive find_by_<field>?

Are the automatically generated find_by_ model methods case
insensitive? (I would presume not.)

If not, is there a way to make them do a case insensitive match, or do
I need to write these by hand with sql?


- Adam

** Expert Technical Project and Business Management
**** System Performance Analysis and Architecture
****** [ http://www.adamfields.com ]

[ Adam Fields (weblog) - - entertaining hundreds of millions of eyeball atoms every day ] … Blog
[ Adam Fields Resume ]… Experience
[ Adam Fields | Flickr ] … Photos
[ http://www.aquicki.com/wiki ]…Wiki

On 8/24/06, Adam F. [email protected] wrote:

Are the automatically generated find_by_ model methods case
insensitive? (I would presume not.)

If not, is there a way to make them do a case insensitive match, or do
I need to write these by hand with sql?

I believe it depends on the database. For example:

Bar.find_by_name ‘Foo’

Division Load (0.002922) SELECT * FROM bars WHERE (bars.“name” =
‘Foo’ ) LIMIT 1

Unless Rails generates different code for different databases
(unlikely in this case), it just depends on how the database
interprets the = operator. PostgreSQL is case sensitive and MySQL is
case insensitive, for example.

If you want to insure case insensitivity:

Bar.find(:first, :conditions=>[‘LOWER(name) = ?’, ‘Foo’.downcase])