sequelize-如何在同一个查询中使用AND和OR运算符?
作者:互联网
我执行以下查询,但出现错误.我想要我最后发布的SQL查询的结果.
userServiceAppointmentModel.findAll({
where: {
technician_id: resultsFromAuthentication.technician_id,
is_confirmed_by_user: 1,
$or: {
service_start_time: {
gte: curLocalDate
},
service_running_status: 1
}
},
attributes: attributes
}).complete(function (err, appointmentResponse) {
if (err) {
console.log(err);
}
SELECT
`id`, `technician_id`, `user_id`, `service_id`, `service_name`,
`service_location_string`, `service_location_latitude`,
`service_location_longitude`, `service_start_time`, `service_end_time`,
`notes`, `total_cost`, `service_cost`, `is_confirmed_by_user`,
`is_confirmed_by_technician`, `service_running_status`,
`service_start_time_by_technician`,`service_complete_time_by_technician`
FROM `user_service_appointment` AS `user_service_appointment`
WHERE `user_service_appointment`.`technician_id`=154
AND `user_service_appointment`.`is_confirmed_by_user`=1
AND (`user_service_appointment`.`service_start_time` >='2015-02-26 01:07'
OR `user_service_appointment`.`service_running_status`=1)
解决方法:
至少对于版本2.0.0,您可以使用Seuqlize.and和Sequelize.or
对于你的情况
..
where: {where: Sequelize.and(
{technician_id: resultsFromAuthentication.technician_id},
{is_confirmed_by_user: 1},
Sequelize.or({
service_start_time: {
gte: curLocalDate
}},
{service_running_status: 1}
)
)
..
标签:sequelize-js,node-js,mysql 来源: https://codeday.me/bug/20191028/1953814.html