ramsey / uuid-doctrine

:snowflake::file_cabinet: Allow the use of a ramsey/uuid UUID as Doctrine field type.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Uuid on api-platform as Primary Key

dadangnh opened this issue · comments

When we use Uuid as Primary Key on API-Platform Project, it shows:

Can't instantiate custom generator : UuidGenerator in . (which is being imported from "/storage/dadangnh/Projects/djp-iam/config/routes/api_platform.yaml"). Make sure there is a loader supporting the "api_platform" type.

Screenshot from 2020-07-13 22-45-37

On the entity, $id was like this:

    /**
     * @var UuidInterface
     *
     * @ORM\Id()
     * @ORM\GeneratedValue(strategy="CUSTOM")
     * @ORM\Column(type="uuid", unique=true)
     * @ORM\CustomIdGenerator(class=UuidGenerator::class)
     */
    private $id;

@dadangnh I also tried this just a few days ago and for me it worked. Did you also add an import statement for the generator class?

use Ramsey\Uuid\Doctrine\UuidGenerator;

@dadangnh I also tried this just a few days ago and for me it worked. Did you also add an import statement for the generator class?

use Ramsey\Uuid\Doctrine\UuidGenerator;

aah this one solve the problem.. I only import the Ramsey\Uuid\UuidInterface but forgot the UuidGenerator..

Thank you, it's worked now