说我有以下计划环回查询,其比较字段值
Product: {
Quantity: Number,
SelledQuantity: Number
}
是否可以写,所有的结果返回的查询在哪里Quantity=SelledQuantity
?
如果是这样,有没有办法使用它时做一个填充? (也许在opts对象的匹配字段内?)
我使用mysql连接器。
说我有以下计划环回查询,其比较字段值
Product: {
Quantity: Number,
SelledQuantity: Number
}
是否可以写,所有的结果返回的查询在哪里Quantity=SelledQuantity
?
如果是这样,有没有办法使用它时做一个填充? (也许在opts对象的匹配字段内?)
我使用mysql连接器。
是的,因为我明白你的问题,你可以通过下面的休息电话做到这一点。 http://localhost:3000/api/products?filter[where][SelledQuantity]=n
这会给你想要的结果。
这个问题更关系到MySQL查询。但你可以通过javascript实现如下:
Product.find({}, fuction(err, products) {
if(err) throw err;
//considering products as array of product. Otherwise you can get to depth for array of product.
var filteredProducts = products.filter(function(p1) {
return p1.Quantity === p1.SelledQuantity;
});
//Your desired output
console.log(filteredProducts);
});
这将会很慢,但会适用于较小的数据库大小。要获得更多优化的答案,请在MySQL部分中提问关于数据库和表结构的问题。
您正在使用哪个连接器? – superkhau
我使用mysql连接器 – irocker