2016-06-27 2 views
-1

3 깊은 관계 루프백 : https://docs.strongloop.com/display/public/LB/Include+filter https://github.com/strongloop/loopback/issues/735쿼리 내가 여기 지침 및 예제에 따라 중첩 된 쿼리를 할 노력하고있어

하지만 난 그게 것으로 예상처럼 작동하지 않습니다. 나는 많은 지사를 가질 수있는 계좌를 가지고 있으며, 많은 인시던트, 위험 평가 및 클레임을 가질 수 있습니다. 지점에서 관련 인시던트, 위험 평가 및 클레임을 쿼리하는 사용자 지정 끝점을 만들었지 만 계정 수준에서 정보를 가져올 수 없습니다. 이것은 단지 나에게 계정을 제공하고, 그러나

Account.find({ 
     where: { 
      id: id, 
     }, 
     include: { 
      relation: 'branches', 
      scope: { 
       include: [ 
        { 
         relation: 'incidents', 
         scope: { 
          where: { 
           incidentDate: { 
            between: [ 
             beginDate, 
             today 
            ] 
           } 
          } 
         } 
        }, 
        { relation: 'riskAssessments' }, 
        { relation: 'claims' } 
       ] 
      } 
     } 
    }, function (err, obj) { 
      if (err) return cb(err); 
      cb(null, obj); 
    }); 

: 여기

Branch.find({ 
     where: { 
      id: id 
     }, 
     include: [ 
      { 
       relation: 'incidents', 
       scope: { 
        where: { 
         incidentDate: { 
          between: [ 
           beginDate, 
           today 
          ] 
         } 
        } 
       } 
      }, 
      { relation: 'riskAssessments' }, 
      { relation: 'claims' } 
}, function (err, obj) { 
     if (err) return cb(err); 
     cb(null, obj); 
}); 

내가 계정에 대한 작업을 기대하는 코드입니다 : 여기

는 지점에 대한 작업 코드 가지의 빈 배열. 이 코드로 실행하면 :

Account.find({ 
     where: { 
      id: id, 
     }, 

     include: { 
      relation: 'branches', 
     } 
},function (err, obj) { 
      if (err) return cb(err); 
      cb(null, obj); 
}); 

관련 브랜치가있는 계정이 나에게 제공됩니다. 추가 할 때마다

scope: { 
    include: { 
     relations: 'riskAssessments', 
    } 
} 

이 작동하지 않고 빈 분기 배열을 반환합니다. 필드와 같은 범위에서 다른 매개 변수를 추가 할 수 있습니다. 예를 들어, 등이 예상대로 작동하며, include를 추가하면됩니다.

답변