mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
DateTime/DateTimeImmutable as an part of composite key
#7176
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 @Greg0 on GitHub (Jul 10, 2023).
Feature Request
Doctrine doesn't support
DateTime/DateTimeImmutableas part of composite primary key.Summary
According to use case https://www.doctrine-project.org/projects/doctrine-orm/en/2.15/tutorials/composite-primary-keys.html#use-case-1-dynamic-attributes
With entity mapping as
Current behaviour
Doctrine throws
How to reproduce
I've added a test case to show the above use case
https://github.com/doctrine/orm/pull/10830
Expected behavior
Allow use
DateTime/DateTimeImmutableat least as a part of the composite key.According to using Enums as part of composite key, in
\Doctrine\ORM\UnitOfWork::getIdHashByIdentifierDateTimeInterface can be casted to string e.g. as->format(DateTimeInterface::ATOM)@stof commented on GitHub (Jul 12, 2023):
Allowing DateTimeImmutable might be possible thanks to the new concept of id hash introduced to support enums.
however, supporting DateTime is a no-go due to its mutable nature (if you mutate the DateTime object, you will still have the same object but a different formatted string for the hash, which would break things)
@stof commented on GitHub (Jul 12, 2023):
And this is not a bug report, but a feature request.
@Greg0 commented on GitHub (Jul 12, 2023):
Should I edit somehow issue to feature request?
Then what should I do next to made this request implemented part of library?
If there are no problem I can try implmenet solution to attached PR with described use case
@greg0ire commented on GitHub (Jul 12, 2023):
No need, I did it for you
as well as a video tutorial showing how to do so yourself for next time 😉
Send a PR for
DateTimeImmutable.Sounds great 👍
@Greg0 commented on GitHub (Jul 17, 2023):
@stof @greg0ire PR is ready to check. I hope it will be good enough. There are some github action checks that should be run again to handle changes.