How to map Id property to Ulid type using yml file?
P粉445750942
P粉445750942 2024-04-01 20:26:47
0
1
551

I'm trying to use a yml file to map the Id property to Symfony\Component\Ulid.

This is my yml file:

App\Entity\User:
  type: entity
  repositoryClass: App\Entity\UserRepository
  table: user
  id:
    id:
      type: ulid
      unique: true
      generator:
        strategy: CUSTOM
        class: Symfony\Component\Uid\Ulid

When I run the command to generate "migrations" I get the following error: "Cannot instantiate custom generator, no class defined"

How to use yml file to map Id attribute to Ulid type?

The following mapping using PHP 8 attributes is valid:

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Uid\Ulid;

class User
{
    #[ORM\Id]
    #[ORM\Column(type: 'ulid', unique: true)]
    #[ORM\GeneratedValue(strategy: 'CUSTOM')]
    #[ORM\CustomIdGenerator(class: 'doctrine.ulid_generator')]
    private $id;

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

}

But I need to use yml mapping.

P粉445750942
P粉445750942

reply all(1)
P粉638343995

My solution is as follows:

App\Entity\User: 
  type: entity 
  repositoryClass: App\Repository\UserRepository 
  table: "`user`"
  id:
    id:
      type: ulid
      unique: true
      generator:
        strategy: CUSTOM
      customIdGenerator:
        class: doctrine.ulid_generator
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template