nodeJS loopback包含filter

时间:2016-07-18 12:52:33

标签: node.js loopbackjs

我在查询时遇到了Node JS loop-back包含过滤器的问题。每次都给出响应中的所有记录。但我只想要那些包含我在查询中传递的sportid的记录过滤

 var request = {
     method: 'get',
     command: 'UserPersonalinfos',
     query: {
         filter: {
             "include": {
                 "relation": "UserRegistration",
                  "where": {
                      "sportid": data[0].id
                  }
             },
             limit:5
          }
     },
     headers: {
         access_token:userAccessToken.id,
     }
 };

如果sportid存在,那么它应该返回对象,否则它不应该返回,但在这种情况下,它返回所有UserPersonalinfos个记录并将UserRegistration对象添加到UserPersonalinfos对象

1 个答案:

答案 0 :(得分:0)

根据https://stackoverflow.com/a/32933383/344022,还没有正式提供的内容。确实试图提供它的There is a fork of the loopback-connector by @DiogoDoreto。我没有尝试过,但是如果你要使用它,你会在过滤器中执行以下操作:

  "where": {
    "UserRegistration": {
      "where": {
        "sportid": data[0].id
      }
    }
  }

上面提到的答案也提出了一些其他方法来实现你想要的东西。