How to fetch NULL result from Magento 2 Collection

This is post will helpful to fetch the NULL result value from magento collection.Usually we will use eq, neq, etc…to filter the database column field values into the collection script. Some times we may want to use to fetch the NULL value from the collection.
To fetch the NULL (or) include the NULL filter from the collection then the refer below script. It may helpful more.

 protected function _prepareCollection()  {
 $collection = $this->_myCollectionFactory->create()->setStoreViewId(null);
 $collection->addFieldToFilter('main_table.mobile_type', array('null' => 'null'));
 $this->setCollection($collection);
 return parent::_prepareCollection();
 }

This Script will return the result where mobile_type column is having the NULL value from the table.

Leave a Reply