【问题标题】:LoopBack 3.0: where filter not returning results from REST APILoopBack 3.0:过滤器不从 REST API 返回结果
【发布时间】:2017-11-06 05:10:12
【问题描述】:

我有一个带有单个简单模型的 LoopBack API,如下所示:

{
  "name": "Establishment",
  "base": "PersistedModel",
  "idInjection": true,
  "options": {
    "validateUpsert": true
  },
  "properties": {
    "Distance": {
      "type": "number"
    },
    "EstablishmentId": {
      "type": "number"
    },
    "EstablishmentType": {
      "type": "string"
    },
    "Location": {
      "type": "string"
    },
    "MinCost": {
      "type": "number"
    },
    "Name": {
      "type": "string"
    },
    "Stars": {
      "type": "number"
    },
    "UserRating": {
      "type": "number"
    },
    "UserRatingTitle": {
      "type": "string"
    },
    "UserRatingCount": {
      "type": "number"
    },
    "ImageUrl": {
      "type": "string"
    },
    "ThumbnailUrl": {
      "type": "string"
    }
  },
  "validations": [],
  "relations": {},
  "acls": [],
  "methods": {}
}

http://localhost:3000/api/Establishments 的简单调用会按预期返回所有结果;但是调用http://localhost:3000/api/Establishments?filter[where][distance][gt]=30 根本不会产生任何结果:一个空数组。

有很多Establishments 的Distance 大于30;实际上,在其他属性上使用 where 过滤器也会导致一个空数组。我可能会错过什么?

【问题讨论】:

  • 可能是因为它区分大小写,请尝试将模型上的字段重命名为小写首字母或仅在过滤器中使用“距离”

标签: rest loopbackjs


【解决方案1】:

正如我在评论中提到的,它是区分大小写的,我在我的应用程序上对其进行了更改以确保这一点。

应该是:

http://localhost:3000/api/Establishments?filter[where][Distance][gt]=30

或者你可以试试这个格式:

http://localhost:3000/api/Establishments?filter={"where":{"Distance":{"gt":30}}}

【讨论】:

  • 我的印象是 URL 不区分大小写。无论如何,第一个建议不起作用,第二个仍然返回距离小于 30 的场所。
  • @serlingpa 请将此范围添加到您的机构.json "scope": { "where": { "Distance": {"gt":30} } } 并调用此http://localhost:3000/api/Establishments 是不是相同的结果?
猜你喜欢
  • 2016-12-21
  • 2017-08-07
  • 2022-06-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-02-23
  • 1970-01-01
相关资源
最近更新 更多