Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Setting Data to NULL
 
atoso
Jr. Member
 
Total Posts:  14
Joined:  2008-08-08
 

Hi Community,

How do I set a attribute value to NULL (DATABASE NULL)?
I am a bit embarrassed but i did not find a way to do this.

My Model extends Mage_Core_Model_Abstract

The usual

setData('attribute'$value)
does not work with
setData('attribute'null)

The issue afaik is that
app/code/core/Mage/Core/Model/Mysql4/Abstract.php
Line 406 is commented out
but there must be another way.

protected function _prepareDataForSave(Mage_Core_Model_Abstract $object)
    
{
        $data 
= array();
        
$fields $this->_getWriteAdapter()->describeTable($this->getMainTable());
        foreach (
array_keys($fields) as $field{
            $fieldValue 
$object->getData($field);
            if (
$fieldValue instanceof Zend_Db_Expr{
                $data[$field] 
$fieldValue;
            
}
            
elseif (!is_null($fieldValue)) {
                $data[$field] 
$this->_prepareValueForSave($fieldValue$fields[$field]['DATA_TYPE']);
            
}
            
else {
//                $data[$field] = $fieldValue;
            
}
        }
        
return $data;
    
}

Do i have to use a Zend_Db_Expr set it to NULL ?

Help is ... as always ... very much appreciated

Greets
T.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top