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

Hydrating with enumType as array gives *string* instead of Enum (DQL with join) #10031

Closed
mzk opened this issue Sep 6, 2022 · 4 comments
Closed

Comments

@mzk
Copy link
Contributor

mzk commented Sep 6, 2022

Bug Report

When I have a query:

return $this->entityManager->createQuery('SELECT o.orderStatus FROM Entity\Order o')
            ->getResult(AbstractQuery::HYDRATE_ARRAY);

Then $result[0]['orderStatus'] is instance of BackendEnum OrderStatus.

But when I have a query:

return $this->entityManager->createQuery('SELECT o FROM Entity\Order o')
            ->getResult(AbstractQuery::HYDRATE_ARRAY);

Then $result[0]['orderStatus'] is simple string.

Our Order entity field:

    #[Column(type: Types::STRING, nullable: false, enumType: OrderStatus::class, options: ['charset' => 'utf8', 'collation' => 'utf8_unicode_ci'])]
    private OrderStatus $orderStatus;
Q A
BC Break no
Version 2.13.1

Summary

It should be the same result for both cases.

Current behavior

SELECT o retuns string, SELECT o.orderStatus returns the BackendEnum

How to reproduce

Use entity as described and fetch from query builder as an array.

Expected behavior

SELECT o returns an array that contains BackendEnum.

for ref: #9622

@michnovka
Copy link
Contributor

I generally try to avoid Array Hydration, but I agree that this should work nonetheless. If you use standard object hydration (default) is there any issue?

@mzk
Copy link
Contributor Author

mzk commented Sep 12, 2022

The default object hydration works fine.

@janedbal
Copy link
Contributor

The biggest issue I see here is the same reasoning I wrote in #9622:

Migrating from enums used as custom types to this native form is impossible as it behaves differently

@derrabus
Copy link
Member

Duplicate of #9947

@derrabus derrabus marked this as a duplicate of #9947 Sep 22, 2022
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

4 participants