On 8/24/06, Adam Fields
<rails23049809-CU8A4pfP4hodnm+yROfE0A@public.gmane.org>
wrote:>
> 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])
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---