mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
[Feature] Ablity to write custom change detection logic for custom doctrine types #7496
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 @Arkemlar on GitHub (Apr 16, 2025).
Feature Request
What
Currently, during changeset computation, instances of custom types are compared by
===comparison.My proposal makes it possible to override this behavior. To do so, there must be a way to define a function that does only one thing: compares two values before-and-after.
Why
I seen lots of questions from doctrine users in git hub and stackoverflow like "why changes not detected when I use custom doctrine type?".
And the only answer was: override entity's property with new instance. Well, that's good and correct when we use value objects. But in other cases this is kind of rude way to do things, I think. And sometimes it is painful to write lots of extra code. So my approach reduces pain.
How
I see multiple ways to implement it:
convertToPHPValueandconvertToDatabaseValuemethods, I could also writecompareValuesit will be called instead of using===for comparison. Example:ORM\Columnannotation where I can define comparator - reference to a static function, like so:My personal like to first one by many means.
@Arkemlar commented on GitHub (Apr 17, 2025):
If it's fine, I might implement it.
@arno14 commented on GitHub (Jun 30, 2025):
See https://github.com/doctrine/orm/issues/5542#issuecomment-2521108623