overlookmotel / sequelize-hierarchy

Nested hierarchies for Sequelize
MIT License
302 stars 90 forks source link

Can not set condition for children #230

Open thangnd238 opened 3 years ago

thangnd238 commented 3 years ago

This is my db image

I want to set condition for children, but i receive this error: "Parent ID 2 not found in result set" because the record with id = 2 has status = 2, so can not get in result set. How can i fix it?. This is my code:

data = await Menu.findAll( {
  hierarchy: true,
  where: { status: 1 },
  required: false,
  include: [
    { model: Category },
  ]
}, {
  where: {
    project: project,
    hierarchy_level: 1,
    status: [
      common_const.MENU_STATUS.ACTIVE,
      common_const.MENU_STATUS.DEACTIVE
    ]
  },
} );
overlookmotel commented 3 years ago

@thangnd238 I have reformatted your code to make it more readable. But it doesn't appear to be syntactical - you are calling .findAll() with 2 arguments which (unless Sequelize has changed recently) isn't correct. Can you please check the code is correct?