我正在使用 node.js 和 sequelize 。我想将 createdAt 订购为 DESC。但它不起作用。我该如何解决问题?
这是我的代码:
return AllowedOrganization.findOne({
where,
attributes:[
"fileReviewTimeStamp"
],
include: [
{
model: User,
attributes: [
"firstName",
"lastName",
"npiNumber",
"attestDate"
],
include:[
{
model: PersonalInfo,
attributes: [
"approvalDate"
]
},
{
model:ProviderNotes,
as: "notes",
order:[['createdAt' , 'DESC']],
attributes: [
"createdAt"
]
}
]
}
]
最佳答案
你可以排序
allowedOrganization.User.notes.sort((a,b) => {
const date1 = new Date(a.createdAt)
const date2 = new Date(b.createdAt)
return date2 - date1
})
关于node.js - 按关系中的 DESC 续订顺序不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63957251/