Skip to content

Commit 1ccb8b7

Browse files
authored
fix: Hierarchy View support for ancestors/descendants requests (#1241)
1 parent 5fafe58 commit 1ccb8b7

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

db-service/lib/cqn2sql.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,11 +376,12 @@ class CQN2SQLRenderer {
376376
const expandedByOne = { list: [] } // DistanceTo(...,1)
377377
const expandedByZero = { list: [] } // not DistanceTo(...,null)
378378
let expandedFilter = []
379+
// If a root where exists it should always be DistanceFromRoot otherwise when a recurse.where exists with only DistanceTo() calls
379380
let distanceType = 'DistanceFromRoot'
380381
let distanceVal
381382

382383
if (recurse.where) {
383-
distanceType = 'Distance'
384+
distanceType = where?.length ? 'DistanceFromRoot' : 'Distance'
384385
if (recurse.where[0] === 'and') recurse.where = recurse.where.slice(1)
385386
expandedFilter = [...recurse.where]
386387
collectDistanceTo(expandedFilter)
@@ -463,7 +464,7 @@ class CQN2SQLRenderer {
463464
},
464465
where: expandedFilter.length ? expandedFilter : undefined,
465466
orderBy: [{ ref: ['HIERARCHY_RANK'], sort: 'asc' }],
466-
groupBy: [{ ref: ['NODE_ID'] },{ ref: ['PARENT_ID'] }, { ref: ['HIERARCHY_RANK'] }, { ref: ['HIERARCHY_LEVEL'] }, { ref: ['HIERARCHY_TREE_SIZE'] }, ...columnsOut.filter(c => c.ref)],
467+
groupBy: [{ ref: ['NODE_ID'] }, { ref: ['PARENT_ID'] }, { ref: ['HIERARCHY_RANK'] }, { ref: ['HIERARCHY_LEVEL'] }, { ref: ['HIERARCHY_TREE_SIZE'] }, ...columnsOut.filter(c => c.ref)],
467468
}
468469
}
469470

0 commit comments

Comments
 (0)