【发布时间】:2017-07-31 03:44:03
【问题描述】:
我查看了文档和 github 问题。
https://loopback.io/doc/en/lb2/HasMany-relations.html
https://github.com/strongloop/loopback-datasource-juggler/issues/76
hasMany relation: including from the other direction
我不知道为什么会出现错误:Error: Relation "chatroomID" is not defined for ChatMessage model
似乎即使我正确编辑了我的 json,我的聊天室模型也没有更新(如 REST 资源管理器中所示)
但聊天消息确实设法更新
聊天消息.json
{
"name": "ChatMessage",
"base": "PersistedModel",
"idInjection": true,
"options": {
"relations": {
"ChatRoom": {
"type": "belongsTo",
"model": "ChatRoom",
"foreignKey": "chatroomID"
},
...
聊天室.json
{
"name": "ChatRoom",
"base": "PersistedModel",
"idInjection": true,
"options": {
"relations": {
"chatMessages": {
"type": "hasMany",
"model": "ChatMessages",
"foreignKey": "chatMessagesID"
}
}
},
...
在控制器中:
function getMsgs() {
// http://loopback.io/doc/en/lb2/Include-filter.html
return (
ChatMessage.find({
"filter": {
"include": {
"relation": "chatroomID",
"scope": {
"include": ["ChatRoom"]
}
}
}
})
【问题讨论】:
标签: angularjs loopbackjs has-many strongloop relation