我试图在StrongLoop中创建两个模型之间的关系:用户&集合。
无论我做什么,我就是不能从路径POST: /users/1/collection/
创建一个集合。总是出现相同的错误:
{
"errors": [
{
"status": 404,
"source": "",
"title": "Error",
"code": "",
"detail": "Shared class "user" has no method handling POST /1/collections"
}
]
}
. .搜索了很多次,我终于找到了这个github issue
,展示了如何"修复"。最后我做了必要的修改:
collection.json:
{
"name": "collection",
"base": "PersistedModel",
"strict": false,
"idInjection": false,
"options": {
"validateUpsert": true
},
"properties": {
...
},
"validations": [],
"relations": {
"user": {
"type": "belongsTo",
"model": "user",
"foreignKey": "id"
}
},
"acls": [
{
"accessType": "EXECUTE",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW",
"property": "__create__collections"
}
],
"methods": {}
}
user.json:
{
"name": "user",
"base": "PersistedModel",
"strict": false,
"idInjection": false,
"options": {
"validateUpsert": true
},
"properties": {
...
},
"validations": [],
"relations": {
"collections": {
"type": "hasMany",
"model": "collection",
"foreignKey": "id"
}
},
"acls": [{
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW",
"property": "count"
},
{
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW",
"property": "__create__collections"
},
{
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW",
"property": "__count__collections"
}],
"methods": {}
}
但是…没有工作,我仍然看到相同的错误。
提前感谢!
在" remotemmethod "中,应将http: {path: '/{id}/collection', verb: 'post'}
改为http: {path: '/:id/collection', verb: 'post'}