Gurpinder Gurpinder - 2 years ago 96
MySQL Question

How to use of AND and OR operator in same query in sequelize?

I execute the below query but i gives error. I want the result of my SQL query which i posted at end.

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) {

`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`,
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)

Answer Source

At least for the version 2.0.0 you could use Seuqlize.and and Sequelize.or

for your case

 where: {where: Sequelize.and(
    {technician_id: resultsFromAuthentication.technician_id},
    {is_confirmed_by_user: 1},
            service_start_time: {
                gte: curLocalDate
        {service_running_status: 1}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download