Skip to content

Commit f0562f4

Browse files
authored
Merge pull request #12273 from greg0ire/deprecate-default
Deprecate FieldMapping::$default
2 parents 62f2cff + 96776e0 commit f0562f4

File tree

5 files changed

+13
-4
lines changed

5 files changed

+13
-4
lines changed

UPGRADE.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ and directly start using native lazy objects.
2929

3030
# Upgrade to 3.6
3131

32+
## Deprecate `FieldMapping::$default`
33+
34+
The `default` property of `Doctrine\ORM\Mapping\FieldMapping` is deprecated and
35+
will be removed in 4.0. Instead, use `FieldMapping::$options['default']`.
36+
3237
## Deprecate specifying `nullable` on columns that end up being used in a primary key
3338

3439
Specifying `nullable` on join columns that are part of a primary key is

src/Mapping/ClassMetadata.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2480,9 +2480,9 @@ public function setVersionMapping(array &$mapping): void
24802480

24812481
if (! isset($mapping['default'])) {
24822482
if (in_array($mapping['type'], ['integer', 'bigint', 'smallint'], true)) {
2483-
$mapping['default'] = 1;
2483+
$mapping['options']['default'] = 1;
24842484
} elseif ($mapping['type'] === 'datetime') {
2485-
$mapping['default'] = 'CURRENT_TIMESTAMP';
2485+
$mapping['options']['default'] = 'CURRENT_TIMESTAMP';
24862486
} else {
24872487
throw MappingException::unsupportedOptimisticLockingType($this->name, $mapping['fieldName'], $mapping['type']);
24882488
}

src/Mapping/FieldMapping.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ final class FieldMapping implements ArrayAccess
7171
public string|null $declaredField = null;
7272
public array|null $options = null;
7373
public bool|null $version = null;
74-
public string|int|null $default = null;
74+
75+
/** @deprecated Use options with 'default' key instead */
76+
public string|int|null $default = null;
7577

7678
/**
7779
* @param string $type The type name of the mapped field. Can be one of

src/Tools/SchemaTool.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,9 @@ private function gatherColumn(
484484
$options['scale'] = $mapping->scale;
485485
}
486486

487+
/** @phpstan-ignore property.deprecated */
487488
if (isset($mapping->default)) {
489+
/** @phpstan-ignore property.deprecated */
488490
$options['default'] = $mapping->default;
489491
}
490492

tests/Tests/ORM/Mapping/ClassMetadataBuilderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ public function testCreateVersionedField(): void
247247
FieldMapping::fromMappingArray([
248248
'columnDefinition' => 'foobar',
249249
'columnName' => 'username',
250-
'default' => 1,
250+
'options' => ['default' => 1],
251251
'fieldName' => 'name',
252252
'length' => 124,
253253
'type' => 'integer',

0 commit comments

Comments
 (0)