我有一个自定义用户、角色和角色Map,名为adminuser、adminrole和adminrolemapping。我已经用数据填充了数据库,我正在使用mysql和loopback3.19。我的型号配置是:
{
"name": "AdminRole",
"plural": "adminRoles",
...
"base": "Role",
"relations": {
"users": {
"type": "hasMany",
"model": "AdminUser",
"foreignKey": "principalId",
"through": "AdminRoleMapping"
}
},
...
}
{
"name": "AdminUser",
"plural": "adminUsers",
"base": "User",
...
"roles": {
"type": "hasMany",
"model": "AdminRole",
"foreignKey": "principalId",
"through": "AdminRoleMapping"
}
},
...
}
{
"name": "AdminRoleMapping",
"description": "Map principals to roles",
"plural": "adminRoleMappings",
"base": "RoleMapping",
....
"relations": {
"principal": {
"type": "belongsTo",
"model": "AdminUser",
"foreignKey": "principalId"
},
"roles": {
"type": "belongsTo",
"model": "AdminRole",
"foreignKey": "roleId"
}
},
....
}
当我尝试访问 GET /adminUsers/{id}/roles
然后我得到状态错误500 "message": "Relation \"adminRole\" is not defined for AdminRoleMapping model"
我的设置有什么问题?我已经看过医生了。
1条答案
按热度按时间j9per5c41#
经过一番反复试验,重命名中间表中的关系名称,解决了以下问题: