Object of class Ramsey\Uuid\Lazy\LazyUuidFromString could not be converted to int
nicodemuz opened this issue · comments
Description
I'm just in the process of migrating my database mappings from YAML notation to PHP attributes.
In YAML I used to have the following declaration which worked fine:
token:
type: uuid
generator:
strategy: CUSTOM
customIdGenerator:
class: \Ramsey\Uuid\Doctrine\UuidGenerator
length: 36
unique: true
options:
comment: Unique token to manage this entry without logging in. Used for unsubscribing from emails.
This I converted to a PHP attribute like below:
#[ORM\Column(type: 'uuid', length: 36, unique: true, nullable: false, options: ['comment' => 'Unique token to manage this entry without logging in. Used for unsubscribing from emails.'])]
#[ORM\GeneratedValue(strategy: "CUSTOM")]
#[ORM\CustomIdGenerator(class: UuidGenerator::class)]
private UuidInterface $token;
I have a data fixture that generates this UUID:
$emailSubscriptionEntity->setToken(Uuid::fromString('12345678-1234-1234-1234-1234567890ab'));
When running the data fixtures, the following error appears:
In IntegerType.php line 40:
[ErrorException]
Warning: Object of class Ramsey\Uuid\Lazy\LazyUuidFromString could not be converted to int
Exception trace:
at /home/nico/Projects/online-store/symfony/vendor/doctrine/dbal/src/Types/IntegerType.php:40
Doctrine\DBAL\Types\IntegerType->convertToPHPValue() at /home/nico/Projects/online-store/symfony/vendor/doctrine/dbal/src/Connection.php:1768
Doctrine\DBAL\Connection->convertToPHPValue() at /home/nico/Projects/online-store/symfony/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php:3781
Doctrine\ORM\UnitOfWork->convertSingleFieldIdentifierToPHPValue() at /home/nico/Projects/online-store/symfony/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php:1038
Doctrine\ORM\UnitOfWork->persistNew() at /home/nico/Projects/online-store/symfony/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php:1899
Doctrine\ORM\UnitOfWork->doPersist() at /home/nico/Projects/online-store/symfony/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php:1856
Doctrine\ORM\UnitOfWork->persist() at /home/nico/Projects/online-store/symfony/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php:665
Doctrine\ORM\EntityManager->persist() at /home/nico/Projects/online-store/symfony/src/DataFixtures/PurchaseFixtures.php:230
App\DataFixtures\PurchaseFixtures->load() at /home/nico/Projects/online-store/symfony/vendor/doctrine/data-fixtures/src/Executor/AbstractExecutor.php:123
Doctrine\Common\DataFixtures\Executor\AbstractExecutor->load() at /home/nico/Projects/online-store/symfony/vendor/doctrine/data-fixtures/src/Executor/ORMExecutor.php:26
Doctrine\Common\DataFixtures\Executor\ORMExecutor::Doctrine\Common\DataFixtures\Executor\{closure}() at /home/nico/Projects/online-store/symfony/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php:272
Doctrine\ORM\EntityManager->wrapInTransaction() at /home/nico/Projects/online-store/symfony/vendor/doctrine/data-fixtures/src/Executor/ORMExecutor.php:28
Doctrine\Common\DataFixtures\Executor\ORMExecutor->execute() at /home/nico/Projects/online-store/symfony/vendor/doctrine/doctrine-fixtures-bundle/Command/LoadDataFixturesDoctrineCommand.php:159
Doctrine\Bundle\FixturesBundle\Command\LoadDataFixturesDoctrineCommand->execute() at /home/nico/Projects/online-store/symfony/vendor/symfony/console/Command/Command.php:312
Symfony\Component\Console\Command\Command->run() at /home/nico/Projects/online-store/symfony/vendor/symfony/console/Application.php:1040
Symfony\Component\Console\Application->doRunCommand() at /home/nico/Projects/online-store/symfony/vendor/symfony/framework-bundle/Console/Application.php:88
Symfony\Bundle\FrameworkBundle\Console\Application->doRunCommand() at /home/nico/Projects/online-store/symfony/vendor/symfony/console/Application.php:314
Symfony\Component\Console\Application->doRun() at /home/nico/Projects/online-store/symfony/vendor/symfony/framework-bundle/Console/Application.php:77
Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /home/nico/Projects/online-store/symfony/vendor/symfony/console/Application.php:168
Symfony\Component\Console\Application->run() at /home/nico/Projects/online-store/symfony/bin/console:43
doctrine:fixtures:load [--append] [--group GROUP] [--em EM] [--purger PURGER] [--purge-exclusions PURGE-EXCLUSIONS] [--shard SHARD] [--purge-with-truncate]
Any idea where I'm going wrong?
Environment details
- version of this package: 2.0.0
- PHP version: 8.1.14
- OS: Ubuntu 22.04.2 LTS
It seems to work after I remove:
#[ORM\GeneratedValue(strategy: "CUSTOM")]
#[ORM\CustomIdGenerator(class: UuidGenerator::class)]