mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Enum fields can't be an id field. #7061
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 @johannes85 on GitHub (Oct 14, 2022).
Bug Report
Summary
Id Field with enumType is not working.
Current behavior
I have a entity called "display" with a primary key over multiple columns:
[id] int feedback_id (relation to feedback)
[id] string with enumType identity_type
string identity_id
There also is a parent entity called "feedback" with the following columns:
[id] int id
collection displays (relation to display)
When I query for a entry from feedback with a join to displays, this call failes when done a second time, with:
Object of class App\Entity\IdentityType could not be converted to string
in vendor/doctrine/orm/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php:286
It is caused by this code:
not expecting $data[$fieldName]) to be an enum.
Expected behavior
Support for enum fields as index.
@beberlei commented on GitHub (Oct 15, 2022):
This is the expected behavior at the monent, should work with toString implemented
@johannes85 commented on GitHub (Oct 18, 2022):
There is no way to implement toString for an enum.
@beberlei commented on GitHub (Oct 19, 2022):
I did not know / forgot this, hmmm
@michnovka commented on GitHub (Oct 20, 2022):
Why isnt identifier flattener used in this case?
Check https://github.com/doctrine/orm/pull/9629 this feature should have been already implemented and I am using enum IDs in my project without issue.
Please provide test which shows how its broken.
@flight643 commented on GitHub (Nov 3, 2022):
I am also facing this problem. In my case enum field is a part of the composite primary key. Latest working version is 2.13.1.
I checked #10158 would have fixed the problem if the https://github.com/doctrine/orm/pull/10158#discussion_r999745713 was taken into account
@michnovka commented on GitHub (Nov 3, 2022):
@flight643 please provide broken test case
@tomudding commented on GitHub (Dec 6, 2022):
I am experiencing the same problem on 2.13.4. While our actual implementation is a bit more complex I have been able to abstract it to a failing test case.
PHPunit gives the following information:
L75 of the test case.
I was able to resolve this with a patch that closely resembles the one proposed in #10158 for
ObjectHydrator.@michnovka commented on GitHub (Dec 6, 2022):
I was looking into the code, trying to come up with a fix, but I noticed something weird.
SubComplexChild in your example has just one associationMapping, specifically complex_type. All the other mappings are ignored in UoW, i.e. there is no complex_number nor complexChild_point.
It makes me wonder, is this even a valid syntax:
?
EDIT:
Ok, this syntax was actually OK, but the code is using your PHPDoc syntax and with phpdoc, if you have multiple join columns, you need to wrap them with
ORM\JoinColumns. I fixed this in my test@tomudding commented on GitHub (Dec 6, 2022):
My apologies, we strictly use the attributes in our codebase and I could not be bothered to make my test case to work with that, so I simply copied them into their annotation form not accounting for the need of an
@JoinColumns().Thanks in advance for your time taking a look at this and trying to fix it!
@michnovka commented on GitHub (Dec 6, 2022):
The title of this issue should be "Enum IDs cannot be part of association mapping"