3
votes

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?

1

1 Answers

2
votes

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');