Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Doctrine 2 select empty field

I'm working on a Symfony 2/Doctrine project that has to use a legacy database. I've created a Doctrine 2 entity form the existing database which generally works just fine. But I can't seem to get one case working: There are some database entries that have empty field (not NULL, just empty) which I want to select via a Doctrine query.

$em = $this->getDoctrine()->getManager();
$query = $em->createQuery(
    'SELECT p FROM dtrcmsBundle:Page p WHERE p.articleName = :pageName'
)->setParameter('pageName', '');

Dose not seem to work. Any ideas how to select the empty fields?

like image 524
wowpatrick Avatar asked Jan 26 '26 03:01

wowpatrick


1 Answers

As empty string is less than any character(I may be wrong) so we can compare with the lowest character in the character-encoding scheme, '0'. Following example shows what I mean.

$em = $this->getDoctrine()->getManager();
    $query = $em->createQuery(
    'SELECT p FROM dtrcmsBundle:Page p WHERE p.articleName < :pageName'
)->setParameter('pageName', '0');
like image 176
Turdaliev Nursultan Avatar answered Jan 27 '26 22:01

Turdaliev Nursultan