我有两个模型 - subscribers 和 tags
示例数据:
{
subscribers: [
{
name: "User 1",
tags: ["a","b"]
},
{
name: "User 2",
tags: ["c","d"]
}
]
}
我想根据标签过滤订阅者。
- 如果我给
a
和b
标签,用户 1 应该列出 - 如果我给
a
和c
标签, 用户 1 和用户 2 都应该列出
这是我尝试过的:
方法一:
tags
是 subscribers
模型中的一列,数据类型为数组
/subscribers/?filter={"where":{"tags":{"inq":["a","b"]}}} // doesn't work
方法二:
创建了一个单独的表 tags
并设置 subscribers
有很多 tags
。
/subscribers/?filter={"where":{"tags":{"inq":["a","b"]}}} // doesn't work
如何在不编写自定义方法的情况下在 Loopback 中实现这一点?
我将 Postgresql 作为连接器
最佳答案
更新
如 loopback docs 中所述你应该使用 inq
而不是 In
The inq operator checks whether the value of the specified property matches any of the values provided in an array. The general syntax is: {where: { property: { inq: [val1, val2, ...]}}}
来自这里:
/subscribers/?filter={"where":{"tags":{"In":["a","b"]}}}
对此:
/subscribers/?filter={"where":{"tags":{"inq":["a","b"]}}}
关于node.js - 如何根据 Loopback 中的标签数组过滤订阅者,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52640158/