Skip to content

Commit

Permalink
Fix self referential BelongsTo (again)
Browse files Browse the repository at this point in the history
The test was passing only because UserFactory didn't exist.
  • Loading branch information
guidocella committed Oct 30, 2020
1 parent 8f30248 commit 61f5f9e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ModelPopulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 15 additions & 0 deletions tests/Factories/UserFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace GuidoCella\EloquentPopulator\Factories;

use GuidoCella\EloquentPopulator\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;

class UserFactory extends Factory
{
protected $model = User::class;

public function definition()
{
}
}

0 comments on commit 61f5f9e

Please sign in to comment.