I'm using sequelize 3.24.3 to connect to a MySQL database.
My requirement is to: execute query 1 and then execute query 2 after query 1 completes. Below is the code sample
Student.findOne({
where:{
userID:request.query.userID
}
}).then(function(data){
Papers.findAll({
where:{
userID:request.query.userID
}
}
)
}).then(function (papers) {
response.json({success: true, paper: papers,});
}).catch(function (err) {
console.log(err);
});
When the above runs: after findOne completes it calls the second "then" block and afterwards executes the findAll query. How can I prevent this and have it the queries executed sequentially?
return Papers.findAll({assuming.findAllreturns a promise