Skip to content

How to add if is a leaf node in my nested hierarchies element ? #14569

Discussion options

You must be logged in to vote

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,
  }],
});

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by NicoSan20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants