Skip to content

Commit f4bc859

Browse files
committed
minor #16482 [Uid] Sync generated values docs for: UUIDs and ULIDs (michaelKaefer)
This PR was submitted for the 6.0 branch but it was merged into the 5.4 branch instead. Discussion ---------- [Uid] Sync generated values docs for: UUIDs and ULIDs Updates docs for generated UUIDs (like it is already documented for ULIDs) Commits ------- 5b6abf0 Sync generated values docs for: UUIDs and ULIDs
2 parents 7542cfe + 5b6abf0 commit f4bc859

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

components/uid.rst

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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::
345342
There's also a Doctrine generator to help auto-generate ULID values for the
346343
entity 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

Comments
 (0)