0

After what seems like hours of research, it seems that it's impossible to save a null value to a database column of type int even when it's nullable and defaults to null when the object value is an empty string.

In Varien_Db_Adapter_Pdo_Mysql::prepareColumnValue, it completely ignores a column that's unsigned because it appends "unsigned", like "int unsigned". So when $column['DATA_TYPE'] is analysed it's ignored.

This is critical because we need an empty value to resolve to 0 or null (either would work.

Also, in Mage_Core_Model_Resource_Abstract::_prepareDataForTable, if we can convert '' or '0' to NULL, line 213 would set it to NULL.

Has anyone else found this to be an issue?

1 Answer 1

1

No, I do not face this issue. Column of type int and is nullable can be set to null. You can set it specifically. If you have a model class, then you can check for empty value:

protected function _beforeSave()
{
    if (empty($this->getData('int_param_name')) {
    // or if ($this->getData('int_param_name') === '') {
        $this->setData('int_param_name', null);
    }
    return parent::_beforeSave();
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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