Sequelize - Promise.All返回未定义的数组

时间:2017-07-27 21:41:09

标签: javascript node.js sequelize.js

以下查询成功注销查询结果:

    loans.findAll({
        attributes: option.LoanAttributes,
        include: option.LoanIncludes
      }).then(results => {
      console.log(ExtractQuery(results));
    });

然而,当我将它包装在promise.all函数中时,它返回一个未定义的数组:

    Promise.all([
      loans.findAll({
        attributes: option.LoanAttributes,
        include: option.LoanIncludes
      })
    ]).then(results => {
      console.log(ExtractQuery(results));
    })

1 个答案:

答案 0 :(得分:4)

Promise.all(promiseArraySizeN).then(fulfilledPromiseArraySizeN)

你有一个大小为1的promise数组,因此它将返回一个大小为1的履行的promise数组。因此你需要检查结果[0]。

Promise.all([
  loans.findAll({
    attributes: option.LoanAttributes,
    include: option.LoanIncludes
  })
]).then(results => {
  console.log(ExtractQuery(results[0]))
})