gpt4 book ai didi

node.js - Loopback HasManyThrough 关系仅以一种方式工作

转载 作者:太空宇宙 更新时间:2023-11-03 22:12:48 25 4
gpt4 key购买 nike

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

职位详细信息模型:

{
"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"
}
}

工作场所模型为:

{
"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"
}
}

直通模型定义为

 {
"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"
}
}

当我查询时

    Jobdetails.find({
filter:{
where:{and:[{'status':{neq:3}},{'id':{neq:jobId}}]},
include:'jobvenues'
}
})

工作地点未出现在结果中。但如果我查询

 Jobvenues.find({
filter:{
where:{venueid:jobdetailsId}}]},
include:'jobdetails'
}
})

结果我可以看到相关的工作详细信息......

我引用了很多帖子,包括Strong Loop处的文档

这里Stackoverflow

但无法让我的代码正常工作......

再观察一下...如果我通过 Loopback Explorer 查询并通过GET/Jobdetails/{id}/jobvenues -- 我可以看到相关的工作地点。

但是如果在查询 GET/Jobdetails/{id} 中使用“包含过滤器”,我会得到空的工作地点数组。

最佳答案

尝试添加 keythrough

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


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

关于node.js - Loopback HasManyThrough 关系仅以一种方式工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37106199/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com