Skip to content

fix(doctrine): read the column default option with doctrine/orm 3 - #8705

Merged
soyuka merged 1 commit into
api-platform:5.0from
Maxcastel:fix/doctrine-orm-column-default-option
Oct 16, 2026
Merged

soyuka merged 1 commit into
api-platform:5.0from
Maxcastel:fix/doctrine-orm-column-default-option

Conversation

@Maxcastel

Copy link
Copy Markdown
Contributor
Q A
Branch? 5.0
License MIT

With doctrine/orm 3, #[ORM\Column(options: ['default' => 'draft'])] didn't end up in the property metadata (so no default in the JSON Schema).

We support doctrine/orm 2 and 3:

"doctrine/orm": "^2.17 || ^3.3"

and the factory reads the column default differently for each one:

if (class_exists(FieldMapping::class)) {
$propertyMetadata = $propertyMetadata->withDefault($fieldMapping->default ?? $propertyMetadata->getDefault());
} else {
$propertyMetadata = $propertyMetadata->withDefault($fieldMapping['options']['default'] ?? $propertyMetadata->getDefault());
}

Before

  • doctrine/orm 2: $fieldMapping['options']['default'], works.

  • doctrine/orm 3: $fieldMapping->default, which is deprecated since 3.6 and never filled by the attribute driver. So #[ORM\Column(options: ['default' => 'draft'])] gave no default in the property metadata, nor in the JSON Schema.

    The default property of Doctrine\ORM\Mapping\FieldMapping is deprecated and will be removed in 4.0. Instead, use FieldMapping::$options['default'].

After

doctrine/orm 3 reads options['default'] too, then default as a fallback, like Doctrine's SchemaTool does, so a mapping that sets it keeps working. It's not tied to 3.6, the bug is there on any doctrine/orm 3.

The existing test builds the FieldMapping by hand with ->default, so I added testCreateWithDefaultOptionFromColumnAttribute, which loads the real mapping with the AttributeDriver. Without the fix it fails on 3.3 and 3.6, and passes on 2.17, as expected.

@Maxcastel
Maxcastel force-pushed the fix/doctrine-orm-column-default-option branch from 4bd9f59 to d026356 Compare October 15, 2026 15:10
@soyuka
soyuka merged commit 0aa5088 into api-platform:5.0 Oct 16, 2026
109 of 117 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants