簡體   English   中英

如何通過環回獲取主詳細信息查詢?

[英]How to get a master detail query by loopback?

我有公司和產品model ,從公司到產品模型都有很多關系。 如何使用Get方法獲取company nameID返回所有相關產品的公司信息。

像休閑對象:

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

希望您在公司模型中正確提供了該關系。 如果不是,請查看以下鏈接並創建關系。 在這種情況下,該關系將為屬於。

產品屬於公司

為了查詢相關結果,您有兩種方法。

  • 包括公司的默認模型。 因此,該環回的默認get將返回所有行。 喜歡

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM