@@ -29,6 +29,95 @@ and directly start using native lazy objects.
2929
3030# Upgrade to 3.6
3131
32+ ## Deprecate using string expression for default values in mappings
33+
34+ Using a string expression for default values in field mappings is deprecated.
35+ Use ` Doctrine\DBAL\Schema\DefaultExpression ` instances instead.
36+
37+ Here is how to address this deprecation when mapping entities using PHP attributes:
38+
39+ ``` diff
40+ use DateTime;
41+ + use Doctrine\DBAL\Schema\DefaultExpression\CurrentDate;
42+ + use Doctrine\DBAL\Schema\DefaultExpression\CurrentTime;
43+ + use Doctrine\DBAL\Schema\DefaultExpression\CurrentTimestamp;
44+ use Doctrine\ORM\Mapping as ORM;
45+
46+ #[ORM\Entity]
47+ final class TimeEntity
48+ {
49+ #[ORM\Id]
50+ #[ORM\Column]
51+ public int $id;
52+
53+ - #[ORM\Column(options: ['default' => 'CURRENT_TIMESTAMP'], insertable: false, updatable: false)]
54+ + #[ORM\Column(options: ['default' => new CurrentTimestamp()], insertable: false, updatable: false)]
55+ public DateTime $createdAt;
56+
57+ - #[ORM\Column(options: ['default' => 'CURRENT_TIME'], insertable: false, updatable: false)]
58+ + #[ORM\Column(options: ['default' => new CurrentTime()], insertable: false, updatable: false)]
59+ public DateTime $createdTime;
60+
61+ - #[ORM\Column(options: ['default' => 'CURRENT_DATE'], insertable: false, updatable: false)]
62+ + #[ORM\Column(options: ['default' => new CurrentDate()], insertable: false, updatable: false)]
63+ public DateTime $createdDate;
64+ }
65+ ```
66+
67+ Here is how to do the same when mapping entities using XML:
68+
69+ ``` diff
70+ <?xml version="1.0" encoding="UTF-8"?>
71+
72+ <doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
73+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
74+ xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
75+ https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
76+
77+ <entity name="Doctrine\Tests\ORM\Functional\XmlTimeEntity">
78+ <id name="id" type="integer" column="id">
79+ <generator strategy="AUTO"/>
80+ </id>
81+
82+ <field name="createdAt" type="datetime" insertable="false" updatable="false">
83+ <options>
84+ - <option name="default">CURRENT_TIMESTAMP</option>
85+ + <option name="default">
86+ + <object class="Doctrine\DBAL\Schema\DefaultExpression\CurrentTimestamp"/>
87+ + </option>
88+ </options>
89+ </field>
90+
91+ <field name="createdAtImmutable" type="datetime_immutable" insertable="false" updatable="false">
92+ <options>
93+ - <option name="default">CURRENT_TIMESTAMP</option>
94+ + <option name="default">
95+ + <object class="Doctrine\DBAL\Schema\DefaultExpression\CurrentTimestamp"/>
96+ + </option>
97+ </options>
98+ </field>
99+
100+ <field name="createdTime" type="time" insertable="false" updatable="false">
101+ <options>
102+ - <option name="default">CURRENT_TIME</option>
103+ + <option name="default">
104+ + <object class="Doctrine\DBAL\Schema\DefaultExpression\CurrentTime"/>
105+ + </option>
106+ </options>
107+ </field>
108+ <field name="createdDate" type="date" insertable="false" updatable="false">
109+ <options>
110+ - <option name="default">CURRENT_DATE</option>
111+ + <option name="default">
112+ + <object class="Doctrine\DBAL\Schema\DefaultExpression\CurrentDate"/>
113+ + </option>
114+ </options>
115+ </field>
116+ </entity>
117+ </doctrine-mapping>
118+ ```
119+
120+
32121## Deprecate ` FieldMapping::$default `
33122
34123The ` default ` property of ` Doctrine\ORM\Mapping\FieldMapping ` is deprecated and
0 commit comments