2017-03-09 11 views
1

설명서 및 github 문제를 살펴 보았습니다.루프백 모델이 업데이트되지 않음 - 루프백 : 오류 : 관계 "chatroomID"가 ChatMessage 모델에 정의되지 않았습니다.

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 탐색기에서 볼 수 있음)

enter image description here

하지만 chatmessage 업데이트하는 관리 않았다

enter image description here


채팅 - message.json

{ 
    "name": "ChatMessage", 
    "base": "PersistedModel", 
    "idInjection": true, 
    "options": { 
    "relations": { 
     "ChatRoom": { 
     "type": "belongsTo", 
     "model": "ChatRoom", 
     "foreignKey": "chatroomID" 
     }, 

... 

채팅 - room.json

{ 
    "name": "ChatRoom", 
    "base": "PersistedModel", 
    "idInjection": true, 
    "options": { 
    "relations": { 
     "chatMessages": { 
     "type": "hasMany", 
     "model": "ChatMessages", 
     "foreignKey": "chatMessagesID" 
     } 
    } 
    }, 
... 
컨트롤러 6,

: 쌍방향 관계

function getMsgs() { 
    // http://loopback.io/doc/en/lb2/Include-filter.html 
    return (
    ChatMessage.find({ 
     "filter": { 
     "include": { 
      "relation": "chatroomID", 
      "scope": { 
       "include": ["ChatRoom"] 
      } 
     } 
     } 

}) 

답변

2

외래 키와 동일한 것이다.

또한 관계 모델을 잘못 설정했음을 유의하십시오.

//chat-room.json 
{ 
    "name": "ChatRoom", 
    "base": "PersistedModel", 
    "idInjection": true, 
    "options": { 
    "relations": { 
     "chatMessages": { 
     "type": "hasMany", 
     "model": "ChatMessage", 
     "foreignKey": "chatroomID" 
     } 
    } 
    }, 
... 

그러나 당신이있어 오류가 있기 때문에하지 정의 관계를 포함입니다, 당신은 chatroomID 관계를 해달라고 : 그것은 ChatMessage하지 ChatMessages합니다 ('S')이 같은 변경입니다. chatMessages 관계가 있습니다.

그래서 좋아 변경 : 응답에 대한

ChatRoom.find({ 
     "filter": { 
     "include": { 
      "relation": "chatMessages" 
     } 
     } 
+0

감사합니다. "채팅 메시지가 요청에 대해 처리되지 않았습니다. 필터가 % 7B % 22 포함되었습니다. 22 : % 7B % 22 응답 22 : % 22chatMessages % 22 % 7D % 7D : 오류 : 관계"chatMessages "가 아닙니다. ChatMessage 모델에 정의 됨 ' –

+0

@NatuMyers 아 죄송합니다. 내 잘못이야. 호출 할 모델은'ChatMessage'가 아닌'ChatRoom'입니다. 나는 나의 대답을 업데이트했다. 그것이 잘못된 모델에서 호출 한 코드의 또 다른 문제점입니다. –

+0

많이 고맙습니다 <3 –