EnumType with HYDRATE_ARRAY returns string #7017

Closed
opened 2026-01-22 15:43:13 +01:00 by admin · 0 comments
Owner

Originally created by @janatjak on GitHub (Aug 1, 2022).

Bug Report

DQL with simple entity alias in SELECT part return string instead of enum instance (in HYDRATE_ARRAY mode).

Q A
BC Break no
Version 2.12.x

Current behavior

#[Entity]
class Animal
{
    #[Column, Id, GeneratedValue]
    public int $id = 0;

    #[Column]
    public Status $status = Status::OK;
}

enum Status: string
{
    case OK = 'OK';
    case ERROR = 'ERROR';
}

class AnimalRepository
{
    public function __construct(private readonly EntityManagerInterface $entityManager)
    {
    }

    public function test(): void
    {
        // animal.status is Status enum - OK
        $items1 = $this->entityManager->createQueryBuilder()
            ->select('animal')
            ->from(Animal::class, 'animal')
            ->getQuery()
            ->getResult();

        // animal.status is string - BUG
        $items2 = $this->entityManager->createQueryBuilder()
            ->select('animal')
            ->from(Animal::class, 'animal')
            ->getQuery()
            ->getResult(AbstractQuery::HYDRATE_ARRAY);

        // animal.status is Status enum - OK
        $items3 = $this->entityManager->createQueryBuilder()
            ->select('animal.id, animal.status')
            ->from(Animal::class, 'animal')
            ->getQuery()
            ->getResult();

        // animal.status is Status enum - OK
        $items4 = $this->entityManager->createQueryBuilder()
            ->select('animal.id, animal.status')
            ->from(Animal::class, 'animal')
            ->getQuery()
            ->getResult(AbstractQuery::HYDRATE_ARRAY);
    }
}

Expected behavior

DQL with SELECT entity as root (+ ArrayHydrator) should returns instance of enum.

Originally created by @janatjak on GitHub (Aug 1, 2022). ### Bug Report DQL with simple entity alias in SELECT part return string instead of enum instance (in HYDRATE_ARRAY mode). | Q | A |------------ | ------ | BC Break |no | Version | 2.12.x #### Current behavior ```php #[Entity] class Animal { #[Column, Id, GeneratedValue] public int $id = 0; #[Column] public Status $status = Status::OK; } enum Status: string { case OK = 'OK'; case ERROR = 'ERROR'; } class AnimalRepository { public function __construct(private readonly EntityManagerInterface $entityManager) { } public function test(): void { // animal.status is Status enum - OK $items1 = $this->entityManager->createQueryBuilder() ->select('animal') ->from(Animal::class, 'animal') ->getQuery() ->getResult(); // animal.status is string - BUG $items2 = $this->entityManager->createQueryBuilder() ->select('animal') ->from(Animal::class, 'animal') ->getQuery() ->getResult(AbstractQuery::HYDRATE_ARRAY); // animal.status is Status enum - OK $items3 = $this->entityManager->createQueryBuilder() ->select('animal.id, animal.status') ->from(Animal::class, 'animal') ->getQuery() ->getResult(); // animal.status is Status enum - OK $items4 = $this->entityManager->createQueryBuilder() ->select('animal.id, animal.status') ->from(Animal::class, 'animal') ->getQuery() ->getResult(AbstractQuery::HYDRATE_ARRAY); } } ``` #### Expected behavior DQL with SELECT entity as root (+ ArrayHydrator) should returns instance of enum.
admin closed this issue 2026-01-22 15:43:14 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#7017