Skip to content

[Uid] Removed Uuid generator classes #14951

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 12, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 17 additions & 18 deletions components/uid.rst
Original file line number Diff line number Diff line change
Expand Up @@ -151,40 +151,39 @@ type, which converts to/from UUID objects automatically::
// ...
}

There's also a Doctrine generator to help autogenerate UUID values for the
entity primary keys::
.. versionadded:: 5.2

// there are generators for UUID V1 and V6 too
use Symfony\Bridge\Doctrine\IdGenerator\UuidV4Generator;
use Symfony\Component\Uid\Uuid;
The UUID type was introduced in Symfony 5.2.

/**
* @ORM\Entity(repositoryClass="App\Repository\ProductRepository")
*/
class Product
There is no generator to assign UUIDs automatically as the value of your entity
primary keys, but you can use instead the following::

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
// ...

class User implements UserInterface
{
/**
* @ORM\Id
* @ORM\Column(type="uuid", unique=true)
* @ORM\GeneratedValue(strategy="CUSTOM")
* @ORM\CustomIdGenerator(class=UuidV4Generator::class)
* @ORM\Column(type="ulid", unique=true)
*/
private $id;

// ...
public function __construct()
{
$this->id = new Ulid();
}

public function getId(): ?Uuid
public function getId(): Ulid
{
return $this->id;
}

// ...
}

.. versionadded:: 5.2

The UUID type and generators were introduced in Symfony 5.2.

When using built-in Doctrine repository methods (e.g. ``findOneBy()``), Doctrine
knows how to convert these UUID types to build the SQL query
(e.g. ``->findOneBy(['user' => $user->getUuid()])``). However, when using DQL
Expand Down