How to add if is a leaf node in my nested hierarchies element ? #14569
Answered
by
ephys
NicoSan20
asked this question in
Help & Questions
-
Hi everyone ! Currently I'm using a nested hierarchies like below :
Now, I would like to have on each element found if is an leaf node or not (leaf : true (or false)). How can I do to get this result ? Any help will be appreciated. Thank you in advance. |
Beta Was this translation helpful? Give feedback.
Answered by
ephys
May 30, 2022
Replies: 1 comment
-
The following has not been tested This should return all categories that do not have children (leaves): const result = await models.Category.findAll({
where: {
'$children.id$': null,
},
include: [{
model: models.Category,
as: 'children',
}],
}); This should return all categories that do have children (not leaves): const result = await models.Category.findAll({
include: [{
model: models.Category,
as: 'children',
required: true,
}],
}); |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
NicoSan20
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The following has not been tested
This should return all categories that do not have children (leaves):
This should return all categories that do have children (not leaves):