【发布时间】:2018-06-29 21:54:08
【问题描述】:
我有 2 个模型 Prophet 和 Task,它们有 m:n 关系:
先知
const prophet = sequelize.define('prophets', {
name: {
type: Sequelize.STRING,
primaryKey: true,
unique: true
}
});
prophet.relationship = function(task) {
prophet.belongsToMany(task, {
through: 'prophetTasks',
as: 'tasks',
foreignKey: 'prophetName'
});
};
任务
const task = sequelize.define('tasks', {
name: {
type: Sequelize.STRING,
primaryKey: true,
unique: true
}
});
task.relationship = function(prophet) {
task.belongsToMany(prophet, {
through: 'prophetTasks',
as: 'prophets',
foreignKey: 'taskName'
});
};
编辑: 我的问题是有时我必须更新可能会删除与任务的某些关系的先知,但我不知道如何删除与任何先知没有关系的任务。
我相信我应该找到所有不属于 prophetTasks 表的任务,但我不知道如何使用 sequelize 查询它
【问题讨论】: