我的代码中有这个Promise链,效果很好。文档实际上具有一个值,并且不为null....then(() => { return db.document.findOne({ where: { id: _document.get('id', req.transaction) }, include: [{ model: db.documentChildren, attributes: ['id', 'reference', 'uri', 'contentType', 'type', 'page'] }, { model: db.tag, attributes: ['id', 'key', 'value'], // We don't want meta columns through: { attributes: [] } // Exclude join table }], transaction: req.transaction })}).then(document => { console.log('document = ', document) ...现在,我想将该查询抽象为一个函数,以便可以重复使用。我本来以为这样会行得通,但是由于某些原因,文档始终为空,并且在运行生成的查询时确实会产生结果。当将此查询抽象为自己的函数时,为什么文档为null?function findOneDocumentQuery (db, id, transaction) { return db.document.findOne({ where: { id: id }, include: [{ model: db.documentChildren, attributes: ['id', 'reference', 'uri', 'contentType', 'type', 'page'] }, { model: db.tag, attributes: ['id', 'key', 'value'], // We don't want meta columns through: { attributes: [] } // Exclude join table }], transaction: transaction })}....then(() => { return findOneDocumentQuery(db, _document.get('id', req.transaction)) }).then(document => { console.log('document = ', document)...
1 回答
MYYA
TA贡献1868条经验 获得超4个赞
我认为to的括号findOneDocumentQuery
是错误的,应该是:
return findOneDocumentQuery(db, _document.get('id'), req.transaction);
添加回答
举报
0/150
提交
取消