Skip to content

Commit 3b49add

Browse files
committed
Allow single recursion repeats
1 parent ba522b7 commit 3b49add

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/Model.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,11 +310,11 @@ public function findRelated($tableName, $ids): array
310310
// Check for another Relations model to prevent nesting loops
311311
if ($builder instanceof self)
312312
{
313-
// If nesting is allowed we need to disable this table
313+
// If nesting is allowed we need to disable the target table
314314
if (self::$config->allowNesting)
315315
{
316-
// Add this table to the "without" list
317-
$this->without($this->table);
316+
// Add the table to the "without" list
317+
$this->without($table->name);
318318
$builder->without($this->tmpWithout);
319319
}
320320
// Otherwise turn off relation loading on returned relations

tests/database/RelationsTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,13 @@ public function testNestedRelations()
5151

5252
$this->assertEquals($factory, $servicer->machines[1]->factory);
5353
}
54+
55+
public function testNestedRelationsNotTooDeep()
56+
{
57+
$factories = $this->factories->with('machines')->findAll();
58+
$factory = $this->factories->with(false)->find(1);
59+
60+
$this->assertEquals($factory, $factories[1]->machines[1]->factory);
61+
$this->assertObjectNotHasAttribute('machines', $factories[1]->machines[1]->factory);
62+
}
5463
}

0 commit comments

Comments
 (0)