我有一个预订表,我只想在其中恢复某位教练的所有预订,但要在特定日期并以状态(boolean = true)来恢复。
在我的预订表中,我有一位教练,他只有一个预订,但是请求也让我获得了其他教练的工作时间
我的要求:
Booking.findAll({
attributes: ['booked_time'],
where: {
fk_id_coach: coachId,
[Op.and]: {
booked_date: fullDate,
[Op.and]: {
status: true
}
}
}
}).then(results => {
return res.json({
results
})
此请求将返回我每个教练的所有保留时间...我只想检查一个确切日期且状态为true的教练的保留时间
答案 0 :(得分:1)
不需要嵌套和查询,您可以像这样简单地进行
Booking.findAll({
attributes: ['booked_time'],
where: {
fk_id_coach: coachId,
booked_date: fullDate,
status: true
}
}).then(results => { return res.json({results} )
如果仍然无法正常运行,请发布原始查询,以便我们正确调试。
答案 1 :(得分:0)
谢谢@Vivek Doshi,我找到了其他解决方案:
coach.getBookings({
attributes: ['booked_time'],
where: {
booked_date: fullDate,
[Op.and]: {
status: true
}
}
以更好的方式与协会联系,我没有考虑过 :p