diff --git a/src/ModelPopulator.php b/src/ModelPopulator.php index f4742e3..ee2ac8e 100644 --- a/src/ModelPopulator.php +++ b/src/ModelPopulator.php @@ -198,7 +198,7 @@ protected function associateBelongsTo(array &$formatters, BelongsTo $relation): } // Skip foreign keys for relations of the model to itself to prevent infinite recursion. - if ($relatedClass instanceof $this->model) { + if ($this->model instanceof $relatedClass) { $formatters[$foreignKey] = null; return; diff --git a/tests/Factories/UserFactory.php b/tests/Factories/UserFactory.php new file mode 100644 index 0000000..e862606 --- /dev/null +++ b/tests/Factories/UserFactory.php @@ -0,0 +1,15 @@ +