Skip to content
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

Error retrieving entity with a "Simple array of Enum type" property #11597

Open
Legendary4226 opened this issue Sep 11, 2024 · 0 comments
Open

Comments

@Legendary4226
Copy link

Legendary4226 commented Sep 11, 2024

Bug Report

Q A
BC Break yes/no
Version 3.2.2

Summary

An error while retrieving entities from the database in the case of a multiple enum property created with the Symfony maker.
Error
App\Constant\Enum\MyIntEnum::from(): Argument #1 ($value) must be of type int, string given

Current behavior

TypeError:
App\Constant\Enum\MyIntEnum::from(): Argument #1 ($value) must be of type int, string given

  at C:\path\to\project\vendor\doctrine\orm\src\Internal\Hydration\AbstractHydrator.php:549
  at App\Constant\Enum\MyIntEnum::from('1')
     (C:\path\to\project\vendor\doctrine\orm\src\Internal\Hydration\AbstractHydrator.php:549)
  at Doctrine\ORM\Internal\Hydration\AbstractHydrator::Doctrine\ORM\Internal\Hydration\{closure}('1')
  at array_map(object(Closure), array('1', '2'))
     (C:\path\to\project\vendor\doctrine\orm\src\Internal\Hydration\AbstractHydrator.php:548)
  at Doctrine\ORM\Internal\Hydration\AbstractHydrator->buildEnum(array('1', '2'), 'App\\Constant\\Enum\\MyIntEnum')
     (C:\path\to\project\vendor\doctrine\orm\src\Internal\Hydration\SimpleObjectHydrator.php:143)
  at Doctrine\ORM\Internal\Hydration\SimpleObjectHydrator->hydrateRowData(array('title_1' => 'title', 'content_2' => 'content', 'illustration_3' => binary string, 'links_4' => 'links', 'category_5' => '1,2', 'id_6' => 1, 'uuid_7' => 'ab767b62-b9cf-48eb-9402-0cb304825fbc', 'created_at_8' => '2024-09-11 09:08:48.289139', 'updated_at_9' => '2024-09-11 09:08:48.289130'), array())
     (C:\path\to\project\vendor\doctrine\orm\src\Internal\Hydration\SimpleObjectHydrator.php:59)
  at Doctrine\ORM\Internal\Hydration\SimpleObjectHydrator->hydrateAllData()
     (C:\path\to\project\vendor\doctrine\orm\src\Internal\Hydration\AbstractHydrator.php:168)
  at Doctrine\ORM\Internal\Hydration\AbstractHydrator->hydrateAll(object(Result), object(ResultSetMapping), array('deferEagerLoad' => true))
     (C:\path\to\project\vendor\doctrine\orm\src\Persisters\Entity\BasicEntityPersister.php:937)
  at Doctrine\ORM\Persisters\Entity\BasicEntityPersister->loadAll(array(), null, null, null)
     (C:\path\to\project\vendor\doctrine\orm\src\EntityRepository.php:110)
  at Doctrine\ORM\EntityRepository->findBy(array(), null, null, null)
     (C:\path\to\project\vendor\doctrine\doctrine-bundle\src\Repository\ServiceEntityRepositoryProxy.php:72)
  at Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepositoryProxy->findBy(array())
     (C:\path\to\project\vendor\doctrine\orm\src\EntityRepository.php:96)
  at Doctrine\ORM\EntityRepository->findAll()
     (C:\path\to\project\src\Controller\SuperAdmin\SuperAdminNewsController.php:26)
  at App\Controller\SuperAdmin\SuperAdminNewsController->index(object(NewsRepository))
     (C:\path\to\project\vendor\symfony\http-kernel\HttpKernel.php:183)
  at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 1)
     (C:\path\to\project\vendor\symfony\http-kernel\HttpKernel.php:76)
  at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 1, true)
     (C:\path\to\project\vendor\symfony\http-kernel\Kernel.php:182)
  at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
     (C:\path\to\project\vendor\symfony\runtime\Runner\Symfony\HttpKernelRunner.php:35)
  at Symfony\Component\Runtime\Runner\Symfony\HttpKernelRunner->run()
     (C:\path\to\project\vendor\autoload_runtime.php:29)
  at require_once('C:\\Users\\Admin\\Documents\\vigidomaine\\vendor\\autoload_runtime.php')
     (C:\path\to\project\public\index.php:5)

How to reproduce

The property inside of my entity (generated via the Symfony maker):

#[ORM\Column(type: Types::SIMPLE_ARRAY, enumType: MyIntEnum::class)]
private array $enums = [];

My Enum :

enum MyIntEnum: int
{
   case ONE = 1;
   case TWO = 2;
}

Expected behavior

No errors, the entity is loaded properly with the $enums property as an array of "array<MyIntEnum>"

@Legendary4226 Legendary4226 changed the title Retrieve multiple enum type error Error retrieving entity with a "Simple array of Enum type" property Sep 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant