-
Notifications
You must be signed in to change notification settings - Fork 6
Closed
Description
Checklist before I submit this issue report
I confirm that:
- I have tested this with the latest version available
- I have read documentation @ http://metamodels.readthedocs.org/en/ or http://metamodels.readthedocs.org/de/
- I have checked the Contao community forums for references https://community.contao.org/
- I have checked existing issues for duplicates and found none @ https://github.com/MetaModels/attribute_decimal/issues?q=is%3Aissue
My environment is:
(Please fill in the actual values from your environment)
| Key | Value | Comments |
|---|---|---|
| PHP version: | 7.0 | |
| Contao version: | 3.5.21 | |
| MetaModels version: | hotfix15 | |
| Installation via composer | yes | |
| Installed MetaModels packages | all |
Issue description
When the attribute value is an empty string (''), it will be saved as "0" in the database. Expected behavior would be saving null.
Steps to reproduce
/** @var \MetaModels\IItem $item */
$item->set('decimal-attr', '');
$item->save();This could be added to the attribute class.
public function setDataFor($arrValues)
{
// Translate all '' values to null, so they will not set as `0` in the database.
$arrValues = array_map(function ($value) {
return '' === $value ? null : $value;
}, $arrValues);
parent::setDataFor($arrValues);
}I'm not sure, whether this is a issue, because this does not happen when using the dcg (in the back end).
When this issue will be confirmed, I could provide a PR.
Same for attribute_numeric.