I would like to filter certain fields in my database which are Null, 0, or ''. Unfortunately, using NULL in an IN condition fails to return anything...I believe this is due to NULL comparisons in SQL evaluating as UNKNOWN. For example:
$filterField = $this->Model->find('list', array(
'fields' => array('id','name'),
'recursive' => 0,
'conditions' => array('Model.related_string' => array(Null, 0, '')),
'order' => array('Model.name ASC')
)
);
This always returns no errors and zero rows because the resulting query has SELECT ... WHERE 'Model'.'related_string' IN (NULL, 0, '')
. However, if I want to OR the NULL condition separately, I can't seem to do it with PHP's array syntax. I will overwrite the values. For example:
$conditions['OR'] = array(
'Model.related_string' => array('', 0),
'Model.related_string' => NULL);
Failure. This will only search for NULL entries when the value for the 'Model.related_string' key is overwritten. Am I stuck writing two finds?