What does "no_default" field property mean?

In many field vardef files you can find the property "no_default". I would like to know the purpose and usage of this property as I have found no info about it anywhere.

Thank you very much.

Jaume

PS. I know there is a "default" property that sets the default value for a field. I don't know if the two properties are related in any way.

Parents
  • Hi Jaume Albaigès,

    This property is used by DBManager class to return default value for a field/column if any.

    If this property is set to true, no default value would be returned for the field definition but if it is set to false, function would look out for any 'default' property being set and then return the value appropriately.

    To know more, you can check out getDefaultFromDefinition function inside include/DBManager.php file.

    protected function getDefaultFromDefinition($fieldDef)
    {
        $default = '';
        if (!empty($fieldDef['no_default'])) {
            // nothing to do
        } elseif ($this->getFieldType($fieldDef) == 'bool') {
            if (isset($fieldDef['default'])) {
                $value = (int) isTruthy($fieldDef['default']);
            } else {
                $value = 0;
            }
            $default = " DEFAULT " . $value;
        } elseif (isset($fieldDef['default'])) {
            $default = " DEFAULT " . $this->massageValue($fieldDef['default'], $fieldDef);
        }
        return $default;
    }

    Regards.

Reply
  • Hi Jaume Albaigès,

    This property is used by DBManager class to return default value for a field/column if any.

    If this property is set to true, no default value would be returned for the field definition but if it is set to false, function would look out for any 'default' property being set and then return the value appropriately.

    To know more, you can check out getDefaultFromDefinition function inside include/DBManager.php file.

    protected function getDefaultFromDefinition($fieldDef)
    {
        $default = '';
        if (!empty($fieldDef['no_default'])) {
            // nothing to do
        } elseif ($this->getFieldType($fieldDef) == 'bool') {
            if (isset($fieldDef['default'])) {
                $value = (int) isTruthy($fieldDef['default']);
            } else {
                $value = 0;
            }
            $default = " DEFAULT " . $value;
        } elseif (isset($fieldDef['default'])) {
            $default = " DEFAULT " . $this->massageValue($fieldDef['default'], $fieldDef);
        }
        return $default;
    }

    Regards.

Children