-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Add type inferral for backed enums in Parameter
as part of QueryBuilder
#9372
Comments
Please try out #9373. |
Just for the record, it's unclear to me why the DBAL should know about enums… reading orm/lib/Doctrine/ORM/AbstractQuery.php Lines 431 to 445 in c0a1404
setParameter with an entity, and the DBAL has no knowledge of entities either.
|
@derrabus Thank you for looking into this! I have tested the PR and it works as expected, much appreciated.
@greg0ire My apologies, totally an oversight and misunderstanding on my part! There is indeed no reason that DBAL should be expected to know anything about "complex" objects (potentially passed on from ORM), only data in one of its primitive types. |
I would also like to see this working, as I've just had the same issue, but this time with the findBy / findOneBy methods. On that point, why not just handle this simple conversion inside of Dbal/Connection same as is done with arrays inside of executeQuery? |
Closing because this feature has been implemented in #9373. |
@derrabus I'm unable to test them at this moment. I did look at both MRs and they look good to me, so as soon as 2.12 releases I'll update my project and check. |
Good feature, when can we test it on 2.12.x ? |
Nobody's holding you back. |
Oh yeah I forgot to mention it but it seems it works perfectly fine ever since I upgraded to 2.12. |
Feature Request
Summary
With the release of v2.11.0 just a few hours ago, support for PHP 8.1's enums was added. This works great, however, I would like to see that the
setParameter()
function (or rather theParameter
which is created in that function) has support for automatically inferring the type of backed enums.Here an example:
Then at some point you could want to do something along the of:
However, now you get the following error:
Where I would have expected it to say
integer
.string
is given because it is the default type (\Doctrine\DBAL\ParameterType::STRING
) in\Doctrine\ORM\Query\ParameterTypeInferer::inferType
. Which has no knowledge of what a backed enum is.Clearly, this is also shows that DBAL is incomplete, as it has no idea what to do with the enum (which type of backed enum does not matter, you could force
\Doctrine\DBAL\Types\Types::INTEGER
insetParameter
and DBAL would complain about being unable to convert the enum into an integer). However, that is an separate issue and not what this feature request is about (but it does depend on each other).The text was updated successfully, but these errors were encountered: