从模型中的远程方法中使用find时的环回顺序过滤器,错误:

问题描述 投票:1回答:2

我在远程方法的查找中使用简单的排序过滤器很难:

    /**
 * 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是我模型上的日期类型。

"properties": {
"mealDate": {
  "type": "date",
  "required": true,
  "default": "Date.now"
},

任何想法可能是什么问题?我已经坚持了一段时间,我想解决方案很简单..

P.S - 我知道我可以在数组中使用sort direct来执行此操作,但我在这种情况下尝试使用环回过滤器。

node.js sorting loopbackjs loopback
2个回答
5
投票

基于doc,我认为它应该是这样的:

Meal.find({
  where: {patientId: req.accessToken.userId},
  order: 'mealDate DESC' 
}, cb);

0
投票

环回4:

Meal.find({
  where: {patientId: req.accessToken.userId},
  order: ['mealDate DESC'],
});
© www.soinside.com 2019 - 2024. All rights reserved.