diff --git a/src/Helpers/LTreeHelper.php b/src/Helpers/LTreeHelper.php index aaaba5c..a73ddd1 100644 --- a/src/Helpers/LTreeHelper.php +++ b/src/Helpers/LTreeHelper.php @@ -93,8 +93,11 @@ public static function pathAsString($path): string public static function getAncestors(Collection $collection): Collection { + if ($collection->count() === 0) { + return new Collection(); + } $first = $collection->first(); - $paths = $collection->pluck('path')->map(function ($item) { + $paths = $collection->pluck($first->getLtreePathColumn())->map(function ($item) { return "'${item}'"; }); $paths = $paths->implode(', '); diff --git a/tests/Functional/LtreeTest.php b/tests/Functional/LtreeTest.php index 53814b0..73937bc 100644 --- a/tests/Functional/LtreeTest.php +++ b/tests/Functional/LtreeTest.php @@ -137,6 +137,7 @@ public function deleteViaServiceSubtree(): void /** @test */ public function ancestors(): void { + $this->assertCount(0, LTreeHelper::getAncestors(new CollectionBase())); $nodes = $this->createTreeNodes($this->getTreeNodes()); $this->assertSame(3, $nodes[1]::ancestorsOf($nodes[6])->get()->count()); $this->assertTrue($nodes[2]->isParentOf(5));