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

ancestors() public method

Named scope. Gets ancestors for node.
public ancestors ( integer $depth = null ) : Phalcon\Mvc\Model\ResultsetInterface
$depth integer the depth.
return Phalcon\Mvc\Model\ResultsetInterface
    public function ancestors($depth = null)
    {
        $owner = $this->getOwner();
        $query = $owner::query()->where($this->leftAttribute . '<' . $owner->{$this->leftAttribute})->andWhere($this->rightAttribute . '>' . $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();
    }