Phalcon\Mvc\Model\Behavior\NestedSet::descendants PHP Method

descendants() public method

Named scope. Gets descendants for node.
public descendants ( integer $depth = null, boolean $addSelf = false ) : Phalcon\Mvc\Model\ResultsetInterface
$depth integer the depth.
$addSelf boolean If TRUE - parent node will be added to result set.
return Phalcon\Mvc\Model\ResultsetInterface
    public function descendants($depth = null, $addSelf = false)
    {
        $owner = $this->getOwner();
        $query = $owner::query()->where($this->leftAttribute . '>' . ($addSelf ? '=' : null) . $owner->{$this->leftAttribute})->andWhere($this->rightAttribute . '<' . ($addSelf ? '=' : null) . $owner->{$this->rightAttribute})->orderBy($this->leftAttribute);
        if ($depth !== null) {
            $query = $query->andWhere($this->levelAttribute . '<=' . ($owner->{$this->levelAttribute} + $depth));
        }
        if ($this->hasManyRoots) {
            $query = $query->andWhere($this->rootAttribute . '=' . $owner->{$this->rootAttribute});
        }
        return $query->execute();
    }