How to do a case insensitive search with multiple elements?


I have a smallish problem

If a = ["Joe","John"]



works well.

Except when the case of the characters is in dispute - how can I make the finder method case insensitive? All the discussions I find concern themselves with the singular case, but not with the case of an array being passed.

Thanks for reading this!


Model.find_all_by_firstname(a.collect{|a| a.downcase})

Will that work if the names in the db include upper case chars? I think the compare in the find needs to be case insensitive rather than what is being compared against being forced to lower case.


As long as you're aware that using LOWER(first_name) will prevent any use of an index on first_name.

You can also look at your particular database to see if it supports a case-insensitive match. MySQL is case-insensitive by default (so I'm guessing that's not what you're using :wink:

If you're using PostgreSQL, you probably could find this via Google:

Note the part that discusses the CITEXT type and the use of an index on the lower(column_name).


Rob Biedenharn