function check_model_owner(field, value, callback) {
Model.find({where: {field: value }}, function(err, models) {
//code
});
}
这段代码是从两个不同的地方调用的,后面的内容对于两个调用都是一样的。
当然这现在中断了,因为 where 子句中的 field
实际上在模型中并不存在,应该由函数参数中的 field
变量代替....我可以这样做吗?
最佳答案
您可以创建查询对象:
function check_model_owner(field, value, callback) {
var query = {};
query[field] = value;
Model.find({where: query}, function(err, models) {
});
}
关于javascript - 如何在where子句中有一个动态查询字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33831174/