@@ -151,40 +151,39 @@ type, which converts to/from UUID objects automatically::
151
151
// ...
152
152
}
153
153
154
- There's also a Doctrine generator to help autogenerate UUID values for the
155
- entity primary keys::
154
+ .. versionadded :: 5.2
156
155
157
- // there are generators for UUID V1 and V6 too
158
- use Symfony\Bridge\Doctrine\IdGenerator\UuidV4Generator;
159
- use Symfony\Component\Uid\Uuid;
156
+ The UUID type was introduced in Symfony 5.2.
160
157
161
- /**
162
- * @ORM\Entity(repositoryClass="App\Repository\ProductRepository")
163
- */
164
- class Product
158
+ There is no generator to assign UUIDs automatically as the value of your entity
159
+ primary keys, but you can use instead the following::
160
+
161
+ namespace App\Entity;
162
+
163
+ use Doctrine\ORM\Mapping as ORM;
164
+ // ...
165
+
166
+ class User implements UserInterface
165
167
{
166
168
/**
167
169
* @ORM\Id
168
- * @ORM\Column(type="uuid", unique=true)
169
- * @ORM\GeneratedValue(strategy="CUSTOM")
170
- * @ORM\CustomIdGenerator(class=UuidV4Generator::class)
170
+ * @ORM\Column(type="ulid", unique=true)
171
171
*/
172
172
private $id;
173
173
174
- // ...
174
+ public function __construct()
175
+ {
176
+ $this->id = new Ulid();
177
+ }
175
178
176
- public function getId(): ?Uuid
179
+ public function getId(): Ulid
177
180
{
178
181
return $this->id;
179
182
}
180
183
181
184
// ...
182
185
}
183
186
184
- .. versionadded :: 5.2
185
-
186
- The UUID type and generators were introduced in Symfony 5.2.
187
-
188
187
When using built-in Doctrine repository methods (e.g. ``findOneBy() ``), Doctrine
189
188
knows how to convert these UUID types to build the SQL query
190
189
(e.g. ``->findOneBy(['user' => $user->getUuid()]) ``). However, when using DQL
0 commit comments