From 401a255a282c3d10f2ac70c50138033f3b0307f8 Mon Sep 17 00:00:00 2001 From: PaulZi Date: Tue, 31 Jul 2018 16:38:08 +0300 Subject: [PATCH] add populateTree with parameter. Close #5 --- NestedSetsBehavior.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/NestedSetsBehavior.php b/NestedSetsBehavior.php index 96339b3..425369c 100644 --- a/NestedSetsBehavior.php +++ b/NestedSetsBehavior.php @@ -215,16 +215,17 @@ class NestedSetsBehavior extends Behavior /** * Populate children relations for self and all descendants * @param int $depth = null + * @param string|array $with = null * @return static */ - public function populateTree($depth = null) + public function populateTree($depth = null, $with = null) { /** @var ActiveRecord[]|static[] $nodes */ - if ($depth === null) { - $nodes = $this->owner->descendants; - } else { - $nodes = $this->getDescendants($depth)->all(); + $query = $this->getDescendants($depth); + if ($with) { + $query->with($with); } + $nodes = $query->all(); $key = $this->owner->getAttribute($this->leftAttribute); $relates = [];