我正在尝试通过以下方式让所有用户及其主供应商、预订和服务在 booking_date 之前订购。
Users.findAll({
where: { id: userId }, attributes: AttributesUser,
include: [{
model: MasterVendor, attributes: AttributesMasterVendor, required: true,
include: [{
model: Bookings, where: { booking_state: jobStatus, booking_date: _date }, attributes: AttributesBooking,
include: [{ model: Services, attributes: attributesService, order: ['Bookings.booking_date'] }],
}],
}],
});
但不幸的是,order by 子句根本没有生成。但是当我尝试按名称获取数据顺序时,它工作得很好
Users.findAll({
where: { id: userId }, attributes: AttributesUser,
include: [{
model: MasterVendor, attributes: AttributesMasterVendor, required: true,
include: [{
model: Bookings, where: { booking_state: jobStatus, booking_date: _date }, attributes: AttributesBooking,
include: { model: Services, attributes: attributesService }
}]
}],
order: ['name'],
});
请建议我,我做错了什么。 谢谢。
最佳答案
试试这个
在订单数组中包含型号名称。
Users.findAll({
where: { id: userId }, attributes: AttributesUser,
include: [{
model: MasterVendor, attributes: AttributesMasterVendor, required: true,
include: [{
model: Bookings, where: { booking_state: jobStatus, booking_date: _date }, attributes: AttributesBooking,
include: { model: Services, attributes: attributesService }
}]
}],
order: [[Bookings, 'booking_date', 'DESC']],
});
关于mysql - 在nodejs中使用关联和排序来 Sequelize findAll,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55109136/