我想通過使用從葉子表中獲取葉子數,sequelize但它給了我未定義的錯誤(讀取'unscoped')。我正在使用 postgresql 和 NodeJS。
這是我的查詢
router.get('/:userId', checkToken, authorize(), async (req, res) => {
try {
const { params } = req;
const { userId } = params;
const leaveCounts = await db.leaves.unscoped().findAll({
attributes: [[db.Sequelize.literal('SELECT count(distinct(id)) from leaves'), 'leaveCount']],
where: {
"userId": {
userId
}
},
raw: true
});
const data = {
leaveCounts
}
res.status(200).json({
data
})
}
catch (e) {
console.log("error in status: ", e)
res.status(500).json({
error: "Internal Server Error",
status: false,
})
}
})
export default router;
錯誤:
error in status: TypeError: Cannot read properties of undefined (reading 'unscoped')
郵遞員回復:
{
"error": "Internal Server Error",
"status": false
}
請幫助如何做到這一點。
uj5u.com熱心網友回復:
leaves物件中的屬性db可能是undefined. 檢查型別db.leaves
前任) console.log(typeof db.leaves)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/410427.html
標籤:
