Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Case insensitive search using findoneby()

I have one repository called $colorMaster

$colorMaster->findOneBy(array('name' => 'RED'));

It returns no records even though in my database there is records with Value "Red".

when i try to use same code with value 'Red'

$colorMaster->findOneBy(array('name' => 'Red'));

it returns value.

Is there any way by which we can get case insensitive records from symfony findOneBy(); so that it can give result using value "RED" also.

like image 514
Ashish Bhanderi Avatar asked Sep 23 '14 13:09

Ashish Bhanderi


1 Answers

Problem is not at Symfony level but at your database level. Some of them are case sensitive and some are not. Yours is case sensitive apparently. To get results, no matter case, try following:

     $name = 'REd'; //case doesn't matter
     $colorMaster->createQueryBuilder('a')
        ->where('upper(a.name) = upper(:name)')
        ->setParameter('name', $name)
        ->getQuery()
        ->execute();
like image 134
Tomasz Madeyski Avatar answered Sep 17 '22 16:09

Tomasz Madeyski