@@ -143,29 +143,26 @@ type, which converts to/from UUID objects automatically::
143143 // ...
144144 }
145145
146- There is no generator to assign UUIDs automatically as the value of your entity
147- primary keys, but you can use the following ::
146+ There's also a Doctrine generator to help auto-generate UUID values for the
147+ entity primary keys::
148148
149149 namespace App\Entity;
150150
151151 use Doctrine\ORM\Mapping as ORM;
152+ use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
152153 use Symfony\Component\Uid\Uuid;
153- // ...
154154
155155 class User implements UserInterface
156156 {
157157 /**
158158 * @ORM\Id
159159 * @ORM\Column(type="uuid", unique=true)
160+ * @ORM\GeneratedValue(strategy="CUSTOM")
161+ * @ORM\CustomIdGenerator(class=UuidGenerator::class)
160162 */
161163 private $id;
162164
163- public function __construct()
164- {
165- $this->id = Uuid::v4();
166- }
167-
168- public function getId(): Uuid
165+ public function getId(): ?Uuid
169166 {
170167 return $this->id;
171168 }
@@ -308,12 +305,12 @@ type, which converts to/from ULID objects automatically::
308305There's also a Doctrine generator to help auto-generate ULID values for the
309306entity primary keys::
310307
308+ namespace App\Entity;
309+
310+ use Doctrine\ORM\Mapping as ORM;
311311 use Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator;
312312 use Symfony\Component\Uid\Ulid;
313313
314- /**
315- * @ORM\Entity(repositoryClass="App\Repository\ProductRepository")
316- */
317314 class Product
318315 {
319316 /**
@@ -324,8 +321,6 @@ entity primary keys::
324321 */
325322 private $id;
326323
327- // ...
328-
329324 public function getId(): ?Ulid
330325 {
331326 return $this->id;
0 commit comments