我有一个contact
db表和模型。 Employee
模型继承自联系。
如果我获取员工/ ,则会返回所有联系人。
如果我只想返回partnerId = 1的联系人,我该如何设置我的employee.json?
{
"name": "employee",
"base": "contact",
"strict": false,
"idInjection": false,
"options": {
"validateUpsert": true,
"postgresql": {
"schema": "public",
"table": "contact"
}
},
"scope": {
"where": {
"partnerId": 1
}
},
//...
}
Debug说调用GET employees /进行以下查询:
SELECT "name", "position", "email", "password", "id" FROM "public"."contact" ORDER BY "id"
似乎没有添加范围。
模型/ partner.json
{
"name": "partner",
// ...
"properties": {
"name": {
"type": "string",
"required": true
},
// ...
},
"validations": [],
"relations": {
"contacts": {
"type": "hasMany",
"model": "contact"
}
//...
},
"acls": [],
"methods": {}
}
答案 0 :(得分:0)
尝试在REST API中使用where过滤器
/employees?filter[where][partnerId]=1
或在您的Employee.js
中Employee.find({ where: {partnerId:1} });