10

I am trying to get the records from database which contains parent_item_id NULL value.

$order_ = $this->_objectManager->create('Vendor\Module\Model\Saleslist')
                    ->getCollection()
            ->addFieldToFilter(
                'order_id',
                $orderId
            )->addFieldToFilter(
                'parent_item_id',
                ['eq' => NULL]
            );

and also want to add the parent_item_id equal NULL or ' ' string check.

19

Try with, array('null' => true)

 $order_ = $this->_objectManager->create('Vendor\Module\Model\Saleslist')
                        ->getCollection()
                ->addFieldToFilter(
                    'order_id',
                    $orderId
                )->addFieldToFilter(
                    'parent_item_id',
                    array('null' => true)
                );
0

There was a bug until Magento 2.3, that prevents to filter a collection by "null" attribute value. https://github.com/magento/magento2/issues/14355

In my case, updating to Magento 2.3 fixed the problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.