@@ -143,29 +143,26 @@ type, which converts to/from UUID objects automatically::
143
143
// ...
144
144
}
145
145
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::
148
148
149
149
namespace App\Entity;
150
150
151
151
use Doctrine\ORM\Mapping as ORM;
152
+ use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
152
153
use Symfony\Component\Uid\Uuid;
153
- // ...
154
154
155
155
class User implements UserInterface
156
156
{
157
157
/**
158
158
* @ORM\Id
159
159
* @ORM\Column(type="uuid", unique=true)
160
+ * @ORM\GeneratedValue(strategy="CUSTOM")
161
+ * @ORM\CustomIdGenerator(class=UuidGenerator::class)
160
162
*/
161
163
private $id;
162
164
163
- public function __construct()
164
- {
165
- $this->id = Uuid::v4();
166
- }
167
-
168
- public function getId(): Uuid
165
+ public function getId(): ?Uuid
169
166
{
170
167
return $this->id;
171
168
}
@@ -308,12 +305,12 @@ type, which converts to/from ULID objects automatically::
308
305
There's also a Doctrine generator to help auto-generate ULID values for the
309
306
entity primary keys::
310
307
308
+ namespace App\Entity;
309
+
310
+ use Doctrine\ORM\Mapping as ORM;
311
311
use Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator;
312
312
use Symfony\Component\Uid\Ulid;
313
313
314
- /**
315
- * @ORM\Entity(repositoryClass="App\Repository\ProductRepository")
316
- */
317
314
class Product
318
315
{
319
316
/**
@@ -324,8 +321,6 @@ entity primary keys::
324
321
*/
325
322
private $id;
326
323
327
- // ...
328
-
329
324
public function getId(): ?Ulid
330
325
{
331
326
return $this->id;
0 commit comments