mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
BackedEnum primary key fails to convert for association using proxy classes #7172
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 @wmouwen on GitHub (Jun 22, 2023).
Bug Report
Summary
For a while BackedEnums were allowed as primary keys, where Doctrine would happily convert them to their scalar value. There has been some back and forth about this in previous issues/PRs where the functionality was repaired and broken again.
https://github.com/doctrine/orm/issues/10334
https://github.com/doctrine/orm/issues/10471
https://github.com/doctrine/orm/pull/10508
Most recent events:
https://github.com/doctrine/orm/issues/10745
https://github.com/doctrine/orm/pull/10758
Current behavior
Setting a BackedEnum as primary key on an entity, using that entity in an association and trying to save it with a proxy class, will throw an error as the BackedEnum is no longer converted to a scalar value.
How to reproduce
See https://github.com/wmouwen/doctrine-orm-10788 for a minimal setup throwing the error.
Code snippet copy 👇
Expected behavior
The BackedEnum is converted and the save succeeds, as it did in version
2.15.2.-edit- Added the stack trace, made the code snippet collapse, added reference to repository with minimal setup.
@wmouwen commented on GitHub (Jun 22, 2023):
@Gwemox Allow me to tag you in this issue as you were the author of the initial pull requests.
@Gwemox commented on GitHub (Jun 22, 2023):
@wmouwen Do you have the stack trace?
@wmouwen commented on GitHub (Jun 22, 2023):
@Gwemox I've created a repository with minimal code which triggers the error. Important to the case is the use of a proxy class. Stack trace is included in the README in the repository.
https://github.com/wmouwen/doctrine-orm-10788
@Gwemox commented on GitHub (Jun 23, 2023):
@wmouwen you can convert your backed enum to string with a doctrine custom type : https://www.doctrine-project.org/projects/doctrine-orm/en/2.15/cookbook/custom-mapping-types.html
@greg0ire @sips-richard We should think about the desired solution for 2.6 or 3.0 ?
Currently StringType does nothing.
$value is a backed enum.
@greg0ire commented on GitHub (Jun 23, 2023):
Well if it's a bug, for 2.15
@Gwemox commented on GitHub (Jun 23, 2023):
We reverted because of this issue https://github.com/doctrine/orm/issues/10745
We could modify the StringType to make a
->valueif it is an enum ? Or create EnumType ?@wmouwen commented on GitHub (Jun 23, 2023):
After having fiddled with custom types for backed enumerations, I would argue having dedicated types isn't the way to go. You would have to differ between the (kinds of) string and integers that there are default mappings for: EnumStringType, EnumIntegerType, optionally EnumSmallintType, etc.
@wmouwen commented on GitHub (Jul 7, 2025):
The bug had been gone for a while without it actually having received a fix. Now, with the return of lazy objects in v3.5, the bug has returned.
If you set
enable_native_lazy_objects = trueandenable_lazy_ghost_objects = false, the conversion from BackedEnum to its backing value no longer occurs.Error
Package versions
@wmouwen commented on GitHub (Jul 14, 2025):
#12063