2016-06-17 53 views
0

我有一个客户端模型,通过InstrumentTracking模型(即“通过”关系)与仪表模型具有许多关系。 如何从控制器代码获取特定客户端的所有工具?我尝试使用client.instruments,它给了我“未定义”,我试图找到与包括'仪器'或'仪器'或'InstrumentTracking'或'instrumentTracking',没有任何工作,任何帮助将不胜感激。loopback - 查询相关模型

+0

你能分享你的代码获取仪器? –

回答

0

好吧,看起来包含应该包含关系本身的名称(在关系中的“客户端”的json文件中,我看到有许多关系被称为“工具”),太糟糕了,strongloop失败在他们的文件中指定它。

最终这工作:

InstrumentTracking.find({ filter: { where: {userID:$rootScope.currentUser.id}, include:['instrument'] }}) 
     .$promise 
     .then(function(foundInst) { 
       var instrument = foundInst[0].instrument; 
       console.log("foundInst="+JSON.stringify(instrument)); 
       $scope.instrumentTracking = instrument; 
      } 
     ); 

但这没有工作(返回空仪阵列):

 Client 
     .find({ filter: { where: {id: $rootScope.currentUser.id}}}) 
     .$promise 
     .then(function(foundUsers) { 
      console.log("foundUsers="+JSON.stringify(foundUsers)); 
      console.log("found == " +JSON.stringify(foundUsers[0])); 
      console.log(" foundUser.instruments = " + foundUsers[0].instruments.find({}).$promise 
        .then(function(foundInst) { 
         console.log("foundInst == " +JSON.stringify(foundInst)); 
        })); 
     }); 

出于某种原因,当我试图从客户端模式,它总是返回空仪器数组,即使我使用API​​ Explorer。