Skip to content

Commit

Permalink
Merge pull request #661 from nextras/misconfiguration-of-pk
Browse files Browse the repository at this point in the history
Add a check of misconfiguration causing infinite recursion
  • Loading branch information
hrach authored Apr 9, 2024
2 parents 5c8248b + d033134 commit 3b71eb8
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 3b71eb8

Please sign in to comment.