2011-09-05 12 views
11

Ho tabella Test:Come interrogare NOT NULL con Doctrine?

Test: 
id | name 
1 | aaa 
2 | 
3 | ccc 
4 | aaa 
5 | 
6 | ddd 

voglio portare in cui il nome non è NULL:

aaa 
ccc 
aaa 
ddd 

Come posso ottenere con:

Doctrine_Core::getTable('Test')->findBy('name', NOTNULL??) <-doesnt working 

e in modello con:

$this->createQuery('u') 
    ->where('name = ?', NOTNULL ???) <- doesnt working 
    ->execute(); 

risposta

27

Prova questo:

$this->createQuery('u') 
    ->where('name IS NOT NULL') 
    ->execute(); 

che è la sintassi SQL standard. Doctrine non converte i valori Null in sql appropriati.

+3

grazie, e come posso usare questo con findby? –

+1

Non è possibile, è necessario scrivere i propri metodi personalizzati. – Dziamid

2

Esegui in modo Doctrine, dal generatore di query e dalla classe Expr.

$qb = $entityManager->createQueryBuilder(); 
$result = $qb->select('t') 
     ->from('Test','t') 
     ->where($qb->expr()->isNotNull('t.name')) 
     ->groupBy('t.name') 
     ->getQuery() 
     ->getResult(); 

ci sono anche la funzione distinta().

Problemi correlati