Magento: Mysql records with NULL values are not fetched in query

· kalpesh

After banging my head on my desk trying to get the records with NULL values with Magento ORM, it was found that writing

$collection->addAttributeToFilter(‘somefield’, ‘null’)  
$collection->addAttributeToFilter(‘somefield’, array(‘is’ => ‘null’))

will check for any blank values like this: WHERE somefield = ”

So if you want to fetch records that have NULL values in Magento style, you need to write as following:

$collection->addAttributeToFilter(‘somefield’, array(‘null’=>’null’)

will check like WHERE somefield = null

Hope this saves someone’s time!

#is null #magento #magento orm #query is null