CakePHP: Find where field is not null

Solution 1:

I think this is what you mean:

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

Solution 2:

Your just missing the null

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

Solution 3:

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

Solution 4:

For simple query:

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

For cakephp 3.X

 $table = TableRegistry::get('Users');
 $assessmentComments = $table
      ->find()
      ->where(function (QueryExpression $exp, Query $q) {
            return $exp->isNotNull('site_url');
        })
      ->all();

Solution 5:

You can also try this,

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

This works fine for me..