Filter 按嵌套数据的环回REST API过滤器

Filter 按嵌套数据的环回REST API过滤器,filter,loopbackjs,loopback,Filter,Loopbackjs,Loopback,我想通过嵌套数据从RESTAPI中过滤。例如,此对象: [ { "name": "Handmade Soft Fish", "tags": "Rubber, Rubber, Salad", "categories": [ { "name": "women", "id": 2, "parent_id": 0, "permalink": "/women" }, {

我想通过嵌套数据从RESTAPI中过滤。例如,此对象:

[
  {
    "name": "Handmade Soft Fish",
    "tags": "Rubber, Rubber, Salad",
    "categories": [
      {
        "name": "women",
        "id": 2,
        "parent_id": 0,
        "permalink": "/women"
      },
      {
        "name": "kids",
        "id": 3,
        "parent_id": 0,
        "permalink": "/kids"
      }
    ]
  },
  {
    "name": "Tasty Rubber Soap",
    "tags": "Granite, Granite, Chair",
    "categories": [
      {
        "name": "kids",
        "id": 3,
        "parent_id": 0,
        "permalink": "/kids"
      }
    ]
  }
]
是否由GET
/api/products提交?过滤器[包括]=类别

而且我只想得到类别名称为“女性”的产品。如何做到这一点?

您能分享一下没有过滤器时的情况吗[include]=categorie,谢谢

[编辑] 在评论中提出几个问题之后,我将构建一个远程方法:在
common/models/myModel.js
(函数内部):

函数getItems(过滤器,分类ID=[]){ 返回新承诺((解决、拒绝)=>{ 让我们包括; if(filter.hasOwnProperty(include)){ if(Array.isArray(filter.include)){ newInclude=[].concat(filter.include,“类别”) }否则{ 如果(filter.include.length>0){ newInclude=[].concat(filter.include,“categories”); }否则{ newInclude=“类别”; } } }否则{ newInclude=“类别”; } myModel.find(Object.assign({},filter,{include:newInclude})) 。然后(数据=>{ if(data.length categories.indexOf(categorie.id)>-1 ) > -1 ); 返回解析(tmp); }) } } myModel.remoteMethod('getItems'{ 接受:[{ arg:“过滤器”, 类型:“对象”, 必填项:true }, { arg:“分类”, 键入:“数组”, 必填项:true }], 返回:{arg:'getItems',类型:'array'} });
我希望它能回答您的问题…

环回不支持基于相关型号的过滤器

不幸的是,这是我们从未解决过的带宽限制:(

有关更多详细信息,请参见此处的讨论和相关问题:

  • 筛选级别2属性:
  • 按相关模型的属性筛选(在查询中使用SQL联接):

您可能希望通过
类别
REST API获取此数据。例如:

GET/api/categories?过滤器[包括]=产品和过滤器[其中][名称]=女性


结果将是一个
类别
对象,所有
产品
都与之相关。为此,需要在模型上声明此关系。

您看到ActiveMQ管理控制台的目的是因为缺少凭据而访问URL,请跳过凭据使用基本身份验证。我写了一篇fab patron命名rest URL。您可以使用类似的名称。

[{“name”:“手工软鱼”、“标签”:“橡胶、橡胶、沙拉”},{“name”:“美味橡胶皂”、“标签”:“花岗岩、花岗岩、椅子”}]
看起来像这样,为什么需要这样做?是出于只读目的还是需要构建那种过滤器来创建/更新/删除?(对不起,我的英语…)那么过滤器[字段][name]=true和过滤器[字段][tags]=true和过滤器[字段][categorieId]=true呢?(请用关系属性的名称替换categorieId)我需要类别页面上的此信息以仅显示给定类别的产品。但是,“类别”这只是一个例子,因为在每个对象中,我有更多的属性,这些属性也有嵌套数据,我可能在其他情况下需要它。这将适用于类别,以及类似情况下的情况,当键不同时,其他嵌套或工作于不同的模型。应该有一些通用性,但感谢您的帮助这是一个nice理念,但每个产品对象也有其他连接,例如变体、选项、图像等。因此,我无法扩展产品的属性
Try like this.It has worked for me.

  const filter = {
          where: {
            'categories.name': {
              inq: ['women']**strong text**
            }
          }
        };

Pass this filter to request as path parameters and the request would be like bellow

GET /api/categoriesfilter=%7B%22where%22:%7B%categories.name%22:%7B%22inq%22:%5B%women%22%5D%7D%7D%7D
Try like this.It has worked for me.

  const filter = {
          where: {
            'categories.name': {
              inq: ['women']**strong text**
            }
          }
        };

Pass this filter to request as path parameters and the request would be like bellow

GET /api/categoriesfilter=%7B%22where%22:%7B%categories.name%22:%7B%22inq%22:%5B%women%22%5D%7D%7D%7D