From d0331343ee5e5ec34ae1d8dd889876c618d72c71 Mon Sep 17 00:00:00 2001 From: Jan Skrasek Date: Tue, 9 Apr 2024 14:58:52 +0200 Subject: [PATCH] add a check of misconfiguration causing infinite recursion --- src/Relationships/HasOne.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Relationships/HasOne.php b/src/Relationships/HasOne.php index 71a26550..93dff880 100644 --- a/src/Relationships/HasOne.php +++ b/src/Relationships/HasOne.php @@ -345,7 +345,15 @@ protected function isChanged(?IEntity $newValue): bool } elseif ($newValue instanceof IEntity && $newValue->isPersisted()) { // value is persisted entity or null // newValue is persisted entity - return $this->getPrimaryValue() !== $newValue->getValue('id'); + $oldValueId = $this->getPrimaryValue(); + $newValueId = $newValue->getValue('id'); + if ($oldValueId !== null && gettype($oldValueId) !== gettype($newValueId)) { + throw new InvalidStateException( + 'The primary value types (' . gettype($oldValueId) . ', ' . gettype($newValueId) + . ') are not equal, possible misconfiguration in entity definition.', + ); + } + return $oldValueId !== $newValueId; } else { // value is persisted entity or null