@@ -166,29 +166,26 @@ type, which converts to/from UUID objects automatically::
166166
167167 The UUID type was introduced in Symfony 5.2.
168168
169- There is no generator to assign UUIDs automatically as the value of your entity
170- primary keys, but you can use the following ::
169+ There's also a Doctrine generator to help auto-generate UUID values for the
170+ entity primary keys::
171171
172172 namespace App\Entity;
173173
174174 use Doctrine\ORM\Mapping as ORM;
175+ use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
175176 use Symfony\Component\Uid\Uuid;
176- // ...
177177
178178 class User implements UserInterface
179179 {
180180 /**
181181 * @ORM\Id
182182 * @ORM\Column(type="uuid", unique=true)
183+ * @ORM\GeneratedValue(strategy="CUSTOM")
184+ * @ORM\CustomIdGenerator(class=UuidGenerator::class)
183185 */
184186 private $id;
185187
186- public function __construct()
187- {
188- $this->id = Uuid::v4();
189- }
190-
191- public function getId(): Uuid
188+ public function getId(): ?Uuid
192189 {
193190 return $this->id;
194191 }
@@ -345,12 +342,12 @@ type, which converts to/from ULID objects automatically::
345342There's also a Doctrine generator to help auto-generate ULID values for the
346343entity primary keys::
347344
345+ namespace App\Entity;
346+
347+ use Doctrine\ORM\Mapping as ORM;
348348 use Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator;
349349 use Symfony\Component\Uid\Ulid;
350350
351- /**
352- * @ORM\Entity(repositoryClass="App\Repository\ProductRepository")
353- */
354351 class Product
355352 {
356353 /**
@@ -361,8 +358,6 @@ entity primary keys::
361358 */
362359 private $id;
363360
364- // ...
365-
366361 public function getId(): ?Ulid
367362 {
368363 return $this->id;
0 commit comments