-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Description
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:
- When I write custom type class with
convertToPHPValueandconvertToDatabaseValuemethods, I could also writecompareValuesit will be called instead of using===for comparison. Example:
class SomeCustomType extends Type
{
public function convertToPHPValue($value, AbstractPlatform $platform) {}
public function convertToPHPValue($value, AbstractPlatform $platform) {}
public function compareValue($valueA, $valueB) {
return $valueA == $valueB;
}
}- Another way is to add extra field to
ORM\Columnannotation where I can define comparator - reference to a static function, like so:
#[ORM\Column(comparator: [SomeClass::class, 'compare'])]
private SomeCustomType $field;My personal like to first one by many means.