围绕循环依赖工作

我尝试了第一次sequelize ,我有一点麻烦让我的数据库模型的工作。

sequelize.sync()失败, Error: Circular Dependency Instruction -> Result => Instruction

这是有道理的,因为我的模型是循环的:

 const Instruction = db.define('instruction', { id: { type: Sequelize.INTEGER, allowNull: false, primaryKey: true, autoIncrement: true, }, /* more keys here */ }); //each instruction results in one or more results const Result = db.define('result', { id: { type: Sequelize.INTEGER, allowNull: false, primaryKey: true, autoIncrement: true, }, /* more keys here */ }); //Relationships //each instruction has one or more results Instruction.hasMany(Result, { as: 'results'} ); //each result has a resulting instruction Result.hasOne(Instruction, { as: 'nextInstruction' }); //each result belongs to a instruction which lead to the result. Result.belongsTo(Instruction, { as: 'originInstruction' }) 

每个指令都有1-n个结果,每个结果都有下一条指令。

林不知道是否有一个更好的方式来build模这个数据库,或者如果我错过了一个方法来使这个工作与续集。 不幸的是,我不是很stream利的SQL,所以它可能是第一个。

任何帮助是极大的赞赏。