Browse Source

add populateTree with parameter. Close #5

master
PaulZi 6 years ago
parent
commit
401a255a28
  1. 11
      NestedSetsBehavior.php

11
NestedSetsBehavior.php

@ -215,16 +215,17 @@ class NestedSetsBehavior extends Behavior
/** /**
* Populate children relations for self and all descendants * Populate children relations for self and all descendants
* @param int $depth = null * @param int $depth = null
* @param string|array $with = null
* @return static * @return static
*/ */
public function populateTree($depth = null) public function populateTree($depth = null, $with = null)
{ {
/** @var ActiveRecord[]|static[] $nodes */ /** @var ActiveRecord[]|static[] $nodes */
if ($depth === null) { $query = $this->getDescendants($depth);
$nodes = $this->owner->descendants; if ($with) {
} else { $query->with($with);
$nodes = $this->getDescendants($depth)->all();
} }
$nodes = $query->all();
$key = $this->owner->getAttribute($this->leftAttribute); $key = $this->owner->getAttribute($this->leftAttribute);
$relates = []; $relates = [];

Loading…
Cancel
Save