javascript - Work Around Circular Dependencys -


i'm trying out sequelize first time , i'm having bit of trouble getting database model work.

sequelize.sync() fails error: circular dependency instruction -> result => instruction

which makes sense since model circular:

const instruction = db.define('instruction', {      id: {              type: sequelize.integer,              allownull: false,              primarykey: true,              autoincrement: true,      },      /* more keys here */  });      //each instruction results in 1 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 1 or more results  instruction.hasmany(result, { as: 'results'} );  //each result has resulting instruction  result.hasone(instruction, { as: 'nextinstruction' });  //each result belongs instruction lead result.  result.belongsto(instruction, { as: 'origininstruction' })

each instruction has 1-n results each result has next instruction.

im not sure whether there better way model database or if i'm missing way makes work sequelize. unfortunately i'm not fluent in sql might first.

any appreciated.


Comments