ramsey / uuid-doctrine

:snowflake::file_cabinet: Allow the use of a ramsey/uuid UUID as Doctrine field type.
MIT License
893 stars 84 forks source link

Fetching metadata from an entity using the custom strategy is throwing an error. #183

Closed christianostrem closed 2 years ago

christianostrem commented 2 years ago

Description

I am trying to fetch metadata from an entity with the Custom Strategy using this library.

This produces an error:

Cannot instantiate custom generator : array ( 'class' => 'UuidGenerator', )

The error is not thrown if i change the strategy to auto.

Steps to reproduce

Put this in a controller and trigger the function.

Get the metadata from an entity. This: "App\Entity\Menu" can be replaced with a entity you have and is using the custom strategy. This: "$this->em" is a refrence to __construct(EntityManagerInterface $em)

$cmf = $this->em->getMetadataFactory();
$class = $cmf->getMetadataFor("App\Entity\Menu");

return new Response("ok");

Expected behavior

Show metadata for the class

Environment details

Php: 8 doctrine: 2.11 Symfony: 6

christianostrem commented 2 years ago

Changing annotation from @ORM\CustomIdGenerator(class=UuidGenerator::class) To @ORM\CustomIdGenerator(class="Ramsey\Uuid\Doctrine\UuidGenerator")

Partially works; I get the metadata printed on screen but then it throws an error.

Cannot instantiate custom generator : array ( 'class' => 'UuidGenerator', )

But is now complaining about this

<?php
use App\Kernel;
require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
christianostrem commented 2 years ago

The issue is now solved. The last issue was that the menu entity had a relation to a file with the wrong annotation.

So the conclusion is that you need to update your documentation for symfony annotation.

You need to change this: @Orm\CustomIdGenerator(class=UuidGenerator::class) To @Orm\CustomIdGenerator(class="Ramsey\Uuid\Doctrine\UuidGenerator")