diff --git a/UPGRADE.md b/UPGRADE.md index 543c5d73d2..5c4808604b 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -29,6 +29,11 @@ and directly start using native lazy objects. # Upgrade to 3.6 +## Deprecate `FieldMapping::$default` + +The `default` property of `Doctrine\ORM\Mapping\FieldMapping` is deprecated and +will be removed in 4.0. Instead, use `FieldMapping::$options['default']`. + ## Deprecate specifying `nullable` on columns that end up being used in a primary key Specifying `nullable` on join columns that are part of a primary key is diff --git a/src/Mapping/ClassMetadata.php b/src/Mapping/ClassMetadata.php index f6c4c66e22..64c148b3c4 100644 --- a/src/Mapping/ClassMetadata.php +++ b/src/Mapping/ClassMetadata.php @@ -2480,9 +2480,9 @@ public function setVersionMapping(array &$mapping): void if (! isset($mapping['default'])) { if (in_array($mapping['type'], ['integer', 'bigint', 'smallint'], true)) { - $mapping['default'] = 1; + $mapping['options']['default'] = 1; } elseif ($mapping['type'] === 'datetime') { - $mapping['default'] = 'CURRENT_TIMESTAMP'; + $mapping['options']['default'] = 'CURRENT_TIMESTAMP'; } else { throw MappingException::unsupportedOptimisticLockingType($this->name, $mapping['fieldName'], $mapping['type']); } diff --git a/src/Mapping/FieldMapping.php b/src/Mapping/FieldMapping.php index f84de2f3b3..ca76057e47 100644 --- a/src/Mapping/FieldMapping.php +++ b/src/Mapping/FieldMapping.php @@ -71,7 +71,9 @@ final class FieldMapping implements ArrayAccess public string|null $declaredField = null; public array|null $options = null; public bool|null $version = null; - public string|int|null $default = null; + + /** @deprecated Use options with 'default' key instead */ + public string|int|null $default = null; /** * @param string $type The type name of the mapped field. Can be one of diff --git a/src/Tools/SchemaTool.php b/src/Tools/SchemaTool.php index 1689f34443..bd72b53620 100644 --- a/src/Tools/SchemaTool.php +++ b/src/Tools/SchemaTool.php @@ -484,7 +484,9 @@ private function gatherColumn( $options['scale'] = $mapping->scale; } + /** @phpstan-ignore property.deprecated */ if (isset($mapping->default)) { + /** @phpstan-ignore property.deprecated */ $options['default'] = $mapping->default; } diff --git a/tests/Tests/ORM/Mapping/ClassMetadataBuilderTest.php b/tests/Tests/ORM/Mapping/ClassMetadataBuilderTest.php index 696b85a7ee..5646865854 100644 --- a/tests/Tests/ORM/Mapping/ClassMetadataBuilderTest.php +++ b/tests/Tests/ORM/Mapping/ClassMetadataBuilderTest.php @@ -247,7 +247,7 @@ public function testCreateVersionedField(): void FieldMapping::fromMappingArray([ 'columnDefinition' => 'foobar', 'columnName' => 'username', - 'default' => 1, + 'options' => ['default' => 1], 'fieldName' => 'name', 'length' => 124, 'type' => 'integer',