Node.js 环回具有许多仅以一种方式工作的粗略关系

Node.js 环回具有许多仅以一种方式工作的粗略关系,node.js,loopbackjs,strongloop,Node.js,Loopbackjs,Strongloop,我有两个模型“Jobdetails”和“JobVinces”,它们通过模型“JobDetailsHasVenues”具有“HasManyThrough”关系 "jobvenues": { "type": "hasMany", "model": "Jobvenues", "foreignKey": "jobdetailsId", "through": "JobdetailsHasVenues", "keyThrough": "venueId" } "jobdetails":

我有两个模型“Jobdetails”和“JobVinces”,它们通过模型“JobDetailsHasVenues”具有“HasManyThrough”关系

"jobvenues": {
  "type": "hasMany",
  "model": "Jobvenues",
  "foreignKey": "jobdetailsId",
  "through": "JobdetailsHasVenues",
  "keyThrough": "venueId"
}


"jobdetails": {
  "type": "hasMany",
  "model": "Jobdetails",
  "foreignKey": "venueId",
  "through": "JobdetailsHasVenues",
  "keyThrough": "jobdetailsId"
}
作业详细信息模型:

{
 "name": "Jobdetails",
 "properties": {
"jobname": {
  "type": "String",
  "required": true,
  "length": 250,
  "precision": null,
  "scale": null,
  "mysql": {
        ---
     },
  "_selectable": false
}
},
"relations": {
"jobvenues": {
  "type": "hasMany",
  "model": "Jobvenues",
  "foreignKey": "jobdetailsId",
  "through": "JobdetailsHasVenues"
}
}
"jobvenues": {
  "type": "hasMany",
  "model": "Jobvenues",
  "foreignKey": "jobdetailsId",
  "through": "JobdetailsHasVenues",
  "keyThrough": "venueId"
}


"jobdetails": {
  "type": "hasMany",
  "model": "Jobdetails",
  "foreignKey": "venueId",
  "through": "JobdetailsHasVenues",
  "keyThrough": "jobdetailsId"
}
工作场所模型如下:

{
"name": "Jobvenues",
"properties": {
"storename": {
  "type": "String",
  "required": true,
  "length": 200,
  "precision": null,
  "scale": null,
  "mysql": {
   ----
   },
  "_selectable": false
}
}
"relations": {
"jobdetails": {
  "type": "hasMany",
  "model": "Jobdetails",
  "foreignKey": "venueId",
  "through": "JobdetailsHasVenues"
   }
}
"jobvenues": {
  "type": "hasMany",
  "model": "Jobvenues",
  "foreignKey": "jobdetailsId",
  "through": "JobdetailsHasVenues",
  "keyThrough": "venueId"
}


"jobdetails": {
  "type": "hasMany",
  "model": "Jobdetails",
  "foreignKey": "venueId",
  "through": "JobdetailsHasVenues",
  "keyThrough": "jobdetailsId"
}
直通模型定义为

 {
  "name": "JobdetailsHasVenues",
   {
    "jobdetailsid": {
     "type": "Number",
     "required": true,
    "length": null,
    "precision": 10
      ---,
    "venueid": {
    "type": "Number",
    "required": true,
    "length": null,
    "precision": 10
     ----
     },
    },
"relations": {
    "jobdetail": {
    "type": "belongsTo",
    "model": "Jobdetails",
    "foreignKey": "jobdetailsId"
   },
   "jobvenue": {
   "type": "belongsTo",
   "model": "Jobvenues",
   "foreignKey": "venueId"
  }
}
"jobvenues": {
  "type": "hasMany",
  "model": "Jobvenues",
  "foreignKey": "jobdetailsId",
  "through": "JobdetailsHasVenues",
  "keyThrough": "venueId"
}


"jobdetails": {
  "type": "hasMany",
  "model": "Jobdetails",
  "foreignKey": "venueId",
  "through": "JobdetailsHasVenues",
  "keyThrough": "jobdetailsId"
}
当我询问

    Jobdetails.find({
      filter:{
        where:{and:[{'status':{neq:3}},{'id':{neq:jobId}}]},
        include:'jobvenues'
          }
       })
"jobvenues": {
  "type": "hasMany",
  "model": "Jobvenues",
  "foreignKey": "jobdetailsId",
  "through": "JobdetailsHasVenues",
  "keyThrough": "venueId"
}


"jobdetails": {
  "type": "hasMany",
  "model": "Jobdetails",
  "foreignKey": "venueId",
  "through": "JobdetailsHasVenues",
  "keyThrough": "jobdetailsId"
}
结果中不存在工作场所。 但如果我质疑

 Jobvenues.find({
      filter:{
        where:{venueid:jobdetailsId}}]},
        include:'jobdetails'
          }
       })
"jobvenues": {
  "type": "hasMany",
  "model": "Jobvenues",
  "foreignKey": "jobdetailsId",
  "through": "JobdetailsHasVenues",
  "keyThrough": "venueId"
}


"jobdetails": {
  "type": "hasMany",
  "model": "Jobdetails",
  "foreignKey": "venueId",
  "through": "JobdetailsHasVenues",
  "keyThrough": "jobdetailsId"
}
因此,我可以看到相关的工作细节

"jobvenues": {
  "type": "hasMany",
  "model": "Jobvenues",
  "foreignKey": "jobdetailsId",
  "through": "JobdetailsHasVenues",
  "keyThrough": "venueId"
}


"jobdetails": {
  "type": "hasMany",
  "model": "Jobdetails",
  "foreignKey": "venueId",
  "through": "JobdetailsHasVenues",
  "keyThrough": "jobdetailsId"
}
我参考了很多帖子,包括网站上的文档

"jobvenues": {
  "type": "hasMany",
  "model": "Jobvenues",
  "foreignKey": "jobdetailsId",
  "through": "JobdetailsHasVenues",
  "keyThrough": "venueId"
}


"jobdetails": {
  "type": "hasMany",
  "model": "Jobdetails",
  "foreignKey": "venueId",
  "through": "JobdetailsHasVenues",
  "keyThrough": "jobdetailsId"
}
这里

"jobvenues": {
  "type": "hasMany",
  "model": "Jobvenues",
  "foreignKey": "jobdetailsId",
  "through": "JobdetailsHasVenues",
  "keyThrough": "venueId"
}


"jobdetails": {
  "type": "hasMany",
  "model": "Jobdetails",
  "foreignKey": "venueId",
  "through": "JobdetailsHasVenues",
  "keyThrough": "jobdetailsId"
}
但我的代码无法正常工作

"jobvenues": {
  "type": "hasMany",
  "model": "Jobvenues",
  "foreignKey": "jobdetailsId",
  "through": "JobdetailsHasVenues",
  "keyThrough": "venueId"
}


"jobdetails": {
  "type": "hasMany",
  "model": "Jobdetails",
  "foreignKey": "venueId",
  "through": "JobdetailsHasVenues",
  "keyThrough": "jobdetailsId"
}
再观察一次。。。如果我通过环回资源管理器查询并通过 GET/Jobdetails/{id}/jobVinces——我可以看到相关的jobVinces

"jobvenues": {
  "type": "hasMany",
  "model": "Jobvenues",
  "foreignKey": "jobdetailsId",
  "through": "JobdetailsHasVenues",
  "keyThrough": "venueId"
}


"jobdetails": {
  "type": "hasMany",
  "model": "Jobdetails",
  "foreignKey": "venueId",
  "through": "JobdetailsHasVenues",
  "keyThrough": "jobdetailsId"
}

但是如果在query GET/Jobdetails/{id}中使用“include filter”,我会得到jobVinces的空数组。

尝试添加keythrough

"jobvenues": {
  "type": "hasMany",
  "model": "Jobvenues",
  "foreignKey": "jobdetailsId",
  "through": "JobdetailsHasVenues",
  "keyThrough": "venueId"
}


"jobdetails": {
  "type": "hasMany",
  "model": "Jobdetails",
  "foreignKey": "venueId",
  "through": "JobdetailsHasVenues",
  "keyThrough": "jobdetailsId"
}