![](/img/trans.png)
[英]how to get nested master-detail or master - detail -detail query in Loopback
[英]How to get a master detail query by loopback?
我有公司和產品model
,從公司到產品模型都有很多關系。 如何使用Get方法獲取company name
或ID
返回所有相關產品的公司信息。
像休閑對象:
[{
"C_name": "tatli",
"address": "TR-IS- aktepe",
"tel": "123456789",
"id": "5a18772e61b6370e4c713b44",
[{
"P_Code": "123456",
"P_name": "screw",
"QTY": 30,
"id": "5a1878af61b6370e4c713b46",
"compny_id": "5a18772e61b6370e4c713b44"
},
{
"P_Code": "123457",
"P_name": "Bead",
"QTY": 33,
"id": "5a1878af61b6370e4c713b47",
"compny_id": "5a18772e61b6370e4c713b44"
}]
}]
希望您在公司模型中正確提供了該關系。 如果不是,請查看以下鏈接並創建關系。 在這種情況下,該關系將為屬於。
產品屬於公司
為了查詢相關結果,您有兩種方法。
company.json模型文件
"relations": { // make sure the name of product model and foreign key is correct
"product": {
"type": "belongsTo",
"model": "product",
"foreignKey": "productId"
}
},
"scope": {
"include": "product"
},
Company.getPrefs = function(id, cb) { Company.find({ where: { }, include: [{relation: 'Product'}] };
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.