I have two Sequelize queries that I need to run in a specific order, the first creates a model and the second creates multiple models from an array. It works in that it inserts obj1
first and then the array of transactions, however the final 'then()' doesn't seem to get called... What am I doing wrong?
var fn = function addTransaction(transaction) {
return new Promise(function() {
return Transaction.create(transaction, { fields: [ 'Id', 'Name' ]});
}
};
var transactions = [...]; //array of transaction objects
Model1.create(obj1, { fields: [ 'Id', 'Name' ,'Description' ]}).then(function() {
var actions = transactions.map(fn);
var results = Promise.all(actions).then(function(data) {
return Promise.all(data.map(fn));
});
results.then(function() {
console.log("Done?"); //not getting called
});
}).catch(function(err) {
console.log(err);
});