diff --git a/src/Eloquent/Traits/HasGraphAdjacencyList.php b/src/Eloquent/Traits/HasGraphAdjacencyList.php index 84f536a..a3d5538 100644 --- a/src/Eloquent/Traits/HasGraphAdjacencyList.php +++ b/src/Eloquent/Traits/HasGraphAdjacencyList.php @@ -265,6 +265,8 @@ public function children(): BelongsToMany $this->getChildKeyName(), $this->getLocalKeyName(), $this->getLocalKeyName() + )->withPivot( + $this->getPivotColumns() ); } @@ -365,6 +367,8 @@ public function parents(): BelongsToMany $this->getParentKeyName(), $this->getLocalKeyName(), $this->getLocalKeyName() + )->withPivot( + $this->getPivotColumns() ); } diff --git a/tests/Graph/EloquentTest.php b/tests/Graph/EloquentTest.php index 2f5ac37..40c2bbc 100644 --- a/tests/Graph/EloquentTest.php +++ b/tests/Graph/EloquentTest.php @@ -42,6 +42,10 @@ public function testChildren() $children = Node::find(1)->children; $this->assertEquals([2, 3, 4, 5], $children->pluck('id')->all()); + $this->assertEquals( + ['parent_id' => 1, 'child_id' => 2, 'label' => 'a', 'weight' => 1, 'created_at' => $this->getFormattedTestNow()], + $children[0]->pivot->getAttributes() + ); } public function testChildrenAndSelf() @@ -60,6 +64,10 @@ public function testParents() $parents = Node::find(5)->parents; $this->assertEquals([1, 2, 10], $parents->pluck('id')->all()); + $this->assertEquals( + ['parent_id' => 1, 'child_id' => 5, 'label' => 'd', 'weight' => 4, 'created_at' => $this->getFormattedTestNow()], + $parents[0]->pivot->getAttributes() + ); } public function testParentsAndSelf()