Forum: Ruby on Rails Condition LIKE with or for autocomplete

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
916981dcb90882ae0f984dc33de0a592?d=identicon&s=25 Felipe Vergara (Guest)
on 2009-01-02 00:13
(Received via mailing list)
Hello!

I need some help. I am doing an auto complete that hast to find result
from
a mysql database of some people if the text written in the text box
matches
the name or last name. It works if i only want to find matches with the
name
or indepently the secon name but not with a or of both.
I have this

@inscritos = Inscrito.find(:all,
        :conditions => ["LOWER(nombre) LIKE ?",
        '%' + params[:familiar]["0"].downcase + '%' ],
        :order => 'apellido ASC',
        :limit => 8)

this works fine but then i want something like this

@inscritos = Inscrito.find(:all,
        :conditions => ["LOWER(nombre) OR LOWER(apellido) LIKE ?",
        '%' + params[:familiar]["0"].downcase + '%' ],
        :order => 'apellido ASC',
        :limit => 8)
--
Felipe Vergara Contesse
Ingeniería Civil Industrial UC
41cc2c53544016a86472343ab3fdc0ff?d=identicon&s=25 Simon Macneall (Guest)
on 2009-01-02 01:07
(Received via mailing list)
Shouldn't it be

@inscritos = Inscrito.find(:all,
          :conditions => ["LOWER(nombre) LIKE ? OR LOWER(apellido) LIKE
?",
          '%' + params[:familiar]["0"].downcase + '%' ],
   '%' + params[:familiar]["0"].downcase + '%' ],
          :order => 'apellido ASC',
          :limit => 8)

otherwise you are saying 'LOWER(nombre) is true or LOWER(apellido) LIKE
blah'

Cheers
Simon

On Fri, 02 Jan 2009 08:12:32 +0900, Felipe Vergara
<felvergara@gmail.com>
Bee69cfed999cd13e3bff73d472a39ee?d=identicon&s=25 Hassan Schroeder (Guest)
on 2009-01-02 01:07
(Received via mailing list)
On Thu, Jan 1, 2009 at 3:12 PM, Felipe Vergara <felvergara@gmail.com>
wrote:
>
> I need some help. I am doing an auto complete that hast to find result from
> a mysql database of some people if the text written in the text box matches
> the name or last name. It works if i only want to find matches with the name
> or indepently the secon name but not with a or of both.

> @inscritos = Inscrito.find(:all,
>         :conditions => ["LOWER(nombre) OR LOWER(apellido) LIKE ?",

I would think that would work if you enclosed your arguments in
parens, e.g.

(LOWER(nombre) OR LOWER(apellido)) LIKE ?

or alternatively

LOWER(nombre) LIKE ? OR LOWER(apellido) LIKE ?

FWIW,
--
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
916981dcb90882ae0f984dc33de0a592?d=identicon&s=25 Felipe Vergara (Guest)
on 2009-01-02 17:00
(Received via mailing list)
I made a concatenation of nombre apellido and then made the search that
worked great.
Thank for your help

--
Felipe Vergara Contesse
Ingeniería Civil Industrial UC
This topic is locked and can not be replied to.