From c47a8be7848889eca53f3281d89d4309a0b92884 Mon Sep 17 00:00:00 2001 From: Sander Muller Date: Tue, 8 Oct 2024 21:39:59 +0200 Subject: [PATCH] Add tree chaperoning to the readme (#264) * Add tree chaperoning to the readme * Apply review suggestion Co-authored-by: Jonas Staudenmeir --------- Co-authored-by: Jonas Staudenmeir --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index 4675e33..aad5416 100644 --- a/README.md +++ b/README.md @@ -176,6 +176,22 @@ $tree = User::tree(3)->get(); $tree = User::treeOf($constraint, 3)->get(); ``` +You can also chaperone tree relations to load parent/ancestor relations already present in the tree to (potentially) reduce 1+n queries: + +```php +$tree = User::tree(3)->get(); + +$tree->loadTreePathRelations(); +``` + +Or via `toTree`: + +```php +$users = User::tree(1)->get(); + +$tree = $users->loadTreePathRelations()->toTree(); +``` + #### Filters The trait provides query scopes to filter models by their position in the tree: