CakePHP: Find where field is not null CakePHP: Find where field is not null php php

CakePHP: Find where field is not null


I think this is what you mean:

$this->User->find('all', array(     'conditions' => array('not' => array('User.site_url' => null))));


Your just missing the null

$this->User->find('all', array('conditions' => array('not' => array('User.site_url'=>null))));


In Cake, a WHERE condition is constructed from 'conditions' element by joining keys and values. That means that you can actually skip providing the keys if you like. E.g.:

array('conditions' => array('User.id'=>1))

is completely equivalent to

array('conditions' => array('User.id = 1'))

Essentially, you can solve your problem by just this:

$this->User->find('all', array('conditions' => array('User.site_url IS NOT NULL')));