egg-sequelize的级联删除

parent为参照表,children外键关联parent。

const parents = await this.ctx.model.Parent.findAll({
    where: { id: parents_id },
    include: [{
        model: this.ctx.model.Children,
        as: 'children',
    }],
});
for (const parent of parents) {
	for (const child of parent.children) {
		child.destroy();
	}
	parent.destroy();
}

你可能感兴趣的:(mysql问题,eggjs,nodejs)