mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Bug: Can't use integers as discriminator values with ORM v3 #7336
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @imba28 on GitHub (Mar 5, 2024).
Bug Report
Summary
A while ago,
0db36a9607stopped implementing type-specific handling when quoting values (Statement::quote()). Moreover, it explicitly added astringtype hint. When trying to upgrade to dbal v4 / orm v3 we noticed that this breaks single table inheritance when configuring integers as discriminator values as briefly outlined in https://github.com/doctrine/orm/discussions/9921.In that case,
SqlWalkerpasses an integer toConnection::quote()when generating the discriminator column SQL condition:c3cc0fdd8c/src/Query/SqlWalker.php (L387)c3cc0fdd8c/src/Query/SqlWalker.php (L2250)This results in a type error.
I guess since we can no longer rely on
doctrine/dbalto resolve the parameters for usdoctrine/ormneeds to somehow consider the discriminator column's type and preprocess the SQL parameters accordingly.Current behavior
When configuring integers as discriminator values Doctrine triggers a type error whenever the application generates queries;
How to reproduce
Here are two functional test that demonstrate the bug:
DiscriminatorColumn(type: 'integer')
DiscriminatorColumn(type: 'string')
Expected behavior
When configuring a discriminator column of type
integerI'd expect all queries to contain unquoted parameters:WHERE type IN (1, 2)Example
However, If I changed the type to
stringI'd like to see the parameters to be quoted instead even if the discriminator values contain numeric strings:WHERE type IN ('1', '2'). This should cover use cases where people are forced to base the inheritance on enums such asENUM('1','2','3')..@imba28 commented on GitHub (Jul 8, 2024):
Fixed by https://github.com/doctrine/orm/pull/11425