Skip to content

Commit

Permalink
add a check of misconfiguration causing infinite recursion
Browse files Browse the repository at this point in the history
  • Loading branch information
hrach committed Apr 9, 2024
1 parent 5c8248b commit e933778
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Relationships/HasOne.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e933778

Please sign in to comment.