<p>You can’t override that method from a plugin, if you really think it should be changed I’d suggest to file a feature request.</p>

<p>As a workaround you could try to set a default manually before the attribute is stored to the database or before the value is used. If it’s for a custom field type you could look into utilizing <a href="https://craftcms.com/classreference/fieldtypes/IFieldType#prepValue-detail" rel="nofollow"><code>prepValue</code></a> or <a href="https://craftcms.com/classreference/fieldtypes/IFieldType#prepValueFromPost-detail" rel="nofollow"><code>prepValueFromPost</code></a> for example.</p>

CC BY-SA 3.0
2016-09-30T10:44:08.490Z
Thank you for your response @carlcs . I'm setting the value in the Field Type settings so `prepValueFromPost` won't apply to this and default value would already be set by the time `prepValue` will be called.
Naveed
CC BY-SA 3.0
2016-09-30T16:07:53.860Z
Do you need to set `default` at all? What I actually had in mind is that you could check in `prepValue` if the value is already set using `is_empty()` or something like that and if that’s the case set the default.
carlcs
CC BY-SA 3.0
2016-10-03T08:47:50.253Z
yeah thats what I did. Many thanks for your help!
Naveed
CC BY-SA 3.0
2016-09-30T09:54:20.067Z
2016-09-30T09:54:20.067Z
carlcs
<p>Following block in <code>generateColumnDefinition($config)</code> function in <code>DbHelper.php</code> class is always converting default value to int if it is a numeric value. A numeric value can be a float so this is causing an issue:</p>

<pre><code>if (isset($config['default']) &amp;&amp; (is_string($config['default']) || is_bool($config['default']) || is_numeric($config['default'])))
{
    if (is_string($config['default']) &amp;&amp; !is_numeric($config['default']))
    {
        $def .= ' DEFAULT "'.$config['default'].'"';
    }
    else
    {
        $def .= ' DEFAULT '.(int)$config['default'];
    }
}
</code></pre>

<p>Is there a way that I can override this method? Any help much appreciated.</p>

<p>Many thanks</p>

<config>
Attribute default value is always being saved as an int
# Attribute default value is always being saved as an int

(Asked by: username_0 on 2016-09-30)

Following block in generateColumnDefinition($config) function in DbHelper.php class is always converting default value to int if it is a numeric value. A numeric value can be a float so this is causing an issue:
if (isset($config['default']) && (is_string($config['default']) || is_bool($config['default']) || is_numeric($config['default'])))
{
    if (is_string($config['default']) && !is_numeric($config['default']))
    {
        $def .= ' DEFAULT "'.$config['default'].'"';
    }
    else
    {
        $def .= ' DEFAULT '.(int)$config['default'];
    }
}

Is there a way that I can override this method? Any help much appreciated.
Many thanks

**Tags:** config

---

## 1 answers

### Answer by username_1 on 2016-09-30. Score: 1 | Accepted answer

You can’t override that method from a plugin, if you really think it should be changed I’d suggest to file a feature request.

As a workaround you could try to set a default manually before the attribute is stored to the database or before the value is used. If it’s for a custom field type you could look into utilizing [`prepValue`](https://craftcms.com/classreference/fieldtypes/IFieldType#prepValue-detail) or [`prepValueFromPost`](https://craftcms.com/classreference/fieldtypes/IFieldType#prepValueFromPost-detail) for example.

> **Comments:**
> **username_0**: Thank you for your response @carlcs . I'm setting the value in the Field Type settings so `prepValueFromPost` won't apply to this and default value would already be set by the time `prepValue` will be called.  
> **username_1**: Do you need to set `default` at all? What I actually had in mind is that you could check in `prepValue` if the value is already set using `is_empty()` or something like that and if that’s the case set the default.  
> **username_0**: yeah thats what I did. Many thanks for your help!  

---

