Magento: Mysql records with NULL values are not fetched in query
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!
2 Comments
Leave a comment
Welcome to my Blog
Certifications
Honor
Recognition
Contributions
Categories
- Apache (2)
- ChatGPT (1)
- Domain name (2)
- eCommerce (2)
- htaccess (1)
- Humor (3)
- Instagram API (1)
- jQuery (4)
- JSON (1)
- Linux (10)
- Magento (142)
- Magento admin (58)
- Magento Certification (5)
- Magento error (13)
- Magento frontend (68)
- Magento Imagine (2)
- Magento Interview (5)
- Magento Master (2)
- Magento2 (10)
- Mobile (1)
- MySQL (7)
- OpenAI (1)
- OroCRM (2)
- Performance (2)
- PHP (8)
- Prototype JS (3)
- Security (4)
- Wordpress (3)
- XML (2)
Tag Cloud
500 internal server error admin answers attribute bug category checkbox checkout cookie customer difference domain name EAV error event extension interview invoice jquery linux magento magento2 magento admin magento error magento interview questions magento orm mysql observer order pinterest product products questions redirect register remove script session simplexml to array state status study guide tax url wordpress
It’s actually not critical that the array value be the string “null”. The value just needs to resolve to true.
Agree, thanks.