diff --git a/src/Storage/DbalNestedSet.php b/src/Storage/DbalNestedSet.php index f5519184..0fb396eb 100644 --- a/src/Storage/DbalNestedSet.php +++ b/src/Storage/DbalNestedSet.php @@ -142,13 +142,19 @@ public function findDescendants(NodeKey $nodeKey, int $depth = 0, int $start = 1 ->orderBy('child.left_pos', 'ASC') ->setParameter('id', $nodeKey->getId()) ->setParameter('revision_id', $nodeKey->getRevisionId()); - if ($start > 0) { - $query->andWhere('child.depth >= :start_depth + parent.depth') - ->setParameter('start_depth', $start); + if ($depth > 0 && $depth == $start) { + $query->andWhere('child.depth = :depth + parent.depth') + ->setParameter('depth', $depth); } - if ($depth > 0) { - $query->andWhere('child.depth <= :depth + parent.depth') - ->setParameter('depth', $start + $depth - 1); + else { + if ($start > 0) { + $query->andWhere('child.depth >= :start_depth + parent.depth') + ->setParameter('start_depth', $start); + } + if ($depth > 0) { + $query->andWhere('child.depth <= :depth + parent.depth') + ->setParameter('depth', $start + $depth - 1); + } } $stmt = $query->executeQuery(); assert($stmt instanceof Result);