【发布时间】:2016-08-20 15:54:35
【问题描述】:
我很难在远程方法的查找中使用简单的排序过滤器:
/**
* This remote method exposes the meals history from the current logged in user
*/
Meal.listMeals = function(req, res, cb) {
Meal.find({
where: {patientId: req.accessToken.userId},
order: {mealDate: 'DESC'}
}, cb);
};
Meal.remoteMethod('listMeals', {
returns: {arg: 'meals', type: 'array'},
http: {path:'/list-meals', verb: 'get'},
accepts: [
{arg: 'req', type: 'object', http: {source: 'req'}},
{arg: 'res', type: 'object', http: {source: 'res'}}
]
});
在您看到我的远程/查找实现的上方,它可以在没有订单过滤器的情况下正常工作。一旦我添加了 oder {mealDate: 'DESC'} 我得到一个错误:
订单 {"mealDate":"DESC"} 无效
mealDate 是我模型上的 Date 类型。
"properties": {
"mealDate": {
"type": "date",
"required": true,
"default": "Date.now"
},
任何想法可能是什么问题?我已经坚持了一段时间,我想解决方案很简单..
P.S - 我知道我可以在数组中直接使用排序来执行此操作,但在这种情况下我尝试使用环回过滤器。
【问题讨论】:
标签: node.js sorting loopbackjs loopback