Issue Bug Closed

#110205Nullable backed enum properties in extbase domain models are persisted as 0 instead of NULL

Jan Kornblum 07/16/26, 08:49 updated 09/08/26, 10:02

Description

Native backed enum support in extbase domain model properties works well in general, but persisting a nullable enum property appears to convert null to 0 in database.

Enum:

enum PriceType: int
{
    case RegularPrice = 0;
    case MemberPrice = 1;
    case SpecialPrice = 2;
}

Model:

class Item extends AbstractEntity
{
    protected ?PriceType $priceType = null;

    public function getPriceType(): ?PriceType
    {
        return $this->priceType;
    }

    public function setPriceType(?PriceType $priceType): void
    {
        $this->priceType = $priceType;
    }
}

Database:

price_type int(11) unsigned DEFAULT NULL

TCA:

'price_type' => [
    'exclude' => true,
    'label' => 'Price type',
    'config' => [
        'type' => 'select',
        'renderType' => 'selectSingle',
        'minitems' => 1,
        'maxitems' => 1,
        'nullable' => true,
        'default' => null,
        'items' => [
            ['label' => '', 'value' => null],
            ['label' => 'Regular', 'value' => 0],
            ['label' => 'Member', 'value' => 1],
            ['label' => 'Special', 'value' => 2],
        ],
    ],
],

Example:

$item = GeneralUtility::makeInstance(Item::class);
// $item->getPriceType() === null

$repository->add($item);
GeneralUtility::makeInstance(PersistenceManager::class)->persistAll();

The nullable enum property was verified to remain null before adding the object to the repository, before calling persistAll(), and after persistAll(). Only the persisted database value changes to 0.

I could reproduce the same behaviour after replacing the TCA with a simple nullable type=number field, so the issue does not seem to be related to selectSingle.

The issue only affects nullable backed enums. Non-nullable enums work as expected.

Reviews 4