protected function subqueryClosureBy($column, $withSelf = false)
    {
        $self = $this;

        return $this->whereIn($this->getQualifiedKeyName(), function ($qb) use ($self, $column, $withSelf) {
            switch ($column) {
                case 'ancestor':
                    $selectedColumn = $self->closure->getAncestorColumn();
                    $whereColumn = $self->closure->getDescendantColumn();
                    break;

                case 'descendant':
                    $selectedColumn = $self->closure->getDescendantColumn();
                    $whereColumn = $self->closure->getAncestorColumn();
                    break;
            }

            $depthOperator = ($withSelf === true ? '>=' : '>');

            return $qb->select($selectedColumn)
                ->from($self->closure->getTable())
                ->where($whereColumn, '=', $self->getKey())
                ->where($self->closure->getDepthColumn(), $depthOperator, 0);
        });
    }