如何在续集中的条件条件下使用,节点js [英] How to use like in where condition in sequelize, node js
本文介绍了如何在续集中的条件条件下使用,节点js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从要使用多个条件的表中过滤数据.当我在查询中应用它显示应用程序错误.怎么做?
I am trying to filter the data from table in which i want to use multiple condition. when i apply like in query it show application error. how to do the same?
我正在使用nodejs框架,express,sequelize和mysql.
I am using nodejs framework, express, sequelize and mysql.
router.get('/booking-information', function (req, res) {
// Get orders
Promise.all([Order.findAll({
/*where: {
endDate: null,
},*/
order: [
['id', 'DESC'],
]
}),
Professional.findAll({where: {status : '1'}})
])
.then(([orders, professionals]) => {
orders.map((order) => {
let professionalsInSameArea = professionals.filter((professional) => {
return (professional.service === order.service || professional.secondary_service LIKE '%' + order.service + '%') && (professional.area === order.area || order.area === professional.secondary_area);
});
order.professionals = [...professionalsInSameArea]
return order;
});
res.render('booking-information', {title: 'Technician', orders: orders, user: req.user});
})
.catch((err) => {
console.error(err);
});
});
我想过滤出订单所在领域和服务相同的专业人员.
I want to filter out the professionals in same area and same service for which a order placed.
推荐答案
Believe it or not, You can just use String.indexOf
function in your case Because
按定义, String LIKE%word%
表示 String
是否包含 word
:
router.get('/booking-information', function (req, res) {
// Get orders
Promise.all([
Order.findAll({
/*where: {
endDate: null,
},*/
order: [
['id', 'DESC'],
]
}),
Professional.findAll({
where: {
status: '1'
}
})
])
.then(([orders, professionals]) => {
orders.map((order) => {
let professionalsInSameArea = professionals.filter((professional) => {
return (professional.service === order.service
|| (professional.secondary_service || '').toLowerCase().indexOf((order.service || '').toLowerCase()) > -1)
&& (professional.area === order.area
|| order.area === professional.secondary_area);
});
order.professionals = professionalsInSameArea; //you don't need to spread, then make an array
return order;
});
res.render('booking-information', { title: 'Technician', orders: orders, user: req.user });
})
.catch((err) => {
console.error(err);
});
});
这篇关于如何在续集中的条件条件下使用,节点js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文