2016-08-13 46 views
0

它是否能夠實現從兩個表如何從兩個表中使用REST請求

得到結構響應程序的功能,我有兩個表獲得結構化JSON包含公司和電話包含每家公司的電話號碼。 一家公司 - >通過companyID

相關的許多手機我需要的正是這種結構:

{ 
    "resource": [ 
    { 
     "companyId": 1, 
     "companyName": "Apple", 
     "companySubject": "Security", 
     "phones": [ 
     { 
      "name": "tel1", 
      "phone": "+178548555" 
     } 
     ] 
    }, 
    { 
     "companyId": 2, 
     "companyName": "Samsung", 
     "companySubject": "IT", 
     "phones": [ 
     { 
      "name": "tel1", 
      "phone": "+178548555" 
     }, 
     { 
      "name": "tel2", 
      "phone": "+178548555" 
     }, 
     { 
      "name": "tel3", 
      "phone": "+178548555" 
     } 
     ] 
    }, 
    { 
     "companyId": 3, 
     "companyName": "LG", 
     "companySubject": "Accounting", 
     "phones": [ 
     { 
      "name": "tel1", 
      "phone": "+178548555" 
     }, 
     { 
      "name": "tel2", 
      "phone": "+178548555" 
     } 
     ] 
    } 
    ] 
} 

問題是,他們在不同的表,我無法弄清楚如何實現它。

我用dreamfactory爲後端

回答

1

如果表有一個外鍵關係(在數據庫中定義),那麼你可以簡單地通過調用get {service_name}/_table/{table_name}?related={relationship_name} 在你上面的例子,這可能是這樣的GET my_service/_table/Company?related=phones_by_companyId獲取手機 您可以通過查看DreamFactory Schema選項卡中的表結構信息來獲取關係名稱,甚至可以爲此關係創建一個別名,以使關係名稱僅爲phonesWorking with related data

如果表格不相關,可以使用DreamFactory的虛擬外鍵來關聯它們。有關VFK的更多信息可以發現on the wiki

相關問題