Skip to content

Commit 7d0ace8

Browse files
committed
Add a new example
1 parent 52d3de5 commit 7d0ace8

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

components/uid.rst

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,35 @@ type, which converts to/from UUID objects automatically::
155155

156156
The UUID type was introduced in Symfony 5.2.
157157

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
167+
{
168+
/**
169+
* @ORM\Id
170+
* @ORM\Column(type="ulid", unique=true)
171+
*/
172+
private $id;
173+
174+
public function __construct()
175+
{
176+
$this->id = new Ulid();
177+
}
178+
179+
public function getId(): Ulid
180+
{
181+
return $this->id;
182+
}
183+
184+
// ...
185+
}
186+
158187
When using built-in Doctrine repository methods (e.g. ``findOneBy()``), Doctrine
159188
knows how to convert these UUID types to build the SQL query
160189
(e.g. ``->findOneBy(['user' => $user->getUuid()])``). However, when using DQL

0 commit comments

Comments
 (0)