2017-05-01 3 views
0

나는이 쿼리를 가지고 :포함 모델에서 루프백의 필드를 필터링하는 방법은 무엇입니까?

UserModel.find({ 

    filter: { 
     include: 
     [ 
      "communications", 
      "roles" 
     ], 
     where : { 
      "object_type" : 1 
     } 
    } 
}, function(data){ 
    $rootScope.users = data; 
}); 

I 필드 "OBJECT_TYPE"에 의해 통신 모델 필터의 모든 데이터를하고 싶지만 내가 원하는대로 작동하지 않습니다.

내 통신 모델은 다음과 같습니다

... 
"properties": { 
"object_type": { 
    "type": "number" 
}, 
"object_id": { 
    "type": "number" 
}, 
"communications_type_code": { 
    "type": "number" 
}, 
"address_type": { 
    "type": "number" 
}, 
"contact_value": { 
    "type": "string" 
}, 
"notes": { 
    "type": "string" 
}, 
.... 

답변

1

관련 모델을 쿼리하려면 관계 범위를 사용해야합니다.

UserModel.find({ 
    filter: { 
     include: 
     [ 
      { 
       "relation": "communications", 
       "scope": { 
       "where": {"object_type": 1} 
       } 

      }, 
      "roles" 
     ] 
    } 
}, function(data){ 
    $rootScope.users = data; 
}); 

확인 문서 "Querying related models"

+0

덕분에 많은 약 : 귀하의 경우에 이런 일이 될 것이라고. 그것은 작동합니다! – oded

0

오디드, 당신이 검색 매개 변수에 filter 속성을 필요로하지 않습니다 생각합니다. 그것은 다음과 같이 읽어야

UserModel.find({ 
    include: [ "communications", "roles" ], 
    where : { "object_type" : 1 } 
}, function(data){ 
    $rootScope.users = data; 
}); 

또한 당신이 include에 추가하는 다른 개체가 쿼리 모델에 관계를 가지고 있는지 확인하십시오. 정말 UserModel일까요, 아니면 CommunicationsModel일까요?

관련 문제