Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento addFieldToFilter allow NULLs

Tags:

magento

When using the Magento collection method addFieldToFilter is it possible to allow filtering by NULL values? I want to select all the products in a collection that have a custom attribute even if no value is assigned to the attribute.

like image 509
leepowers Avatar asked Nov 20 '09 03:11

leepowers


2 Answers

I see you already found a solution, but there is also this option:

$collection->addFieldToFilter('parent_item_id', array('null' => true));

But if you want to use "NULL" => false, which DOESN'T WORK. (and I noticed you can use elements such as "in", "nin", "eq", "neq", "gt"), you can do this:

$collection->addFieldToFilter('parent_item_id', array('neq' => 'NULL' ));

Hope this is still helpful...

like image 197
Kat Avatar answered Nov 16 '22 20:11

Kat


This works for NOT NULL filters

$collection->addFieldToFilter('parent_item_id', array('notnull' => true));
like image 25
Dane Avatar answered Nov 16 '22 19:11

Dane