Case insensitive find_by_<field>?

Are the automatically generated find_by_<field> 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?

Are the automatically generated find_by_<field> 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])