2017-05-25 64 views
0

我使用Laravel與MongoDB中,我在laravel雄辯的關係瞭解甚少,目前我的收藏結構如下Laravel與嵌套列的關係?

collection name:general_details 

{ 
    "id": 01, 
    "personal_details":[ 
     [ 
      "emp_id":10, 
      "blood_group":"B+ve" 
     ], 
     [ 
      "emp_id":11, 
      "blood_group":"B+ve" 
     ] 
    ] 
} 

collection name:employee_details 

{ 
    "emp_id":10, 
    "emp_name":"Alex" 
}, 
{ 
    "emp_id":11, 
    "emp_name":"Ramesh" 
} 

我要創建「EMP_ID」兩個集合之間雄辯關係,請提出任何解決方案?

+0

這兩個表的名稱是什麼? –

+0

GenDetails,EmpDetails的模型名稱 –

回答

0

在GenDetails模式

public function empdetails(){ 
return $this->hasOne('App\EmpDetails'); 
} 

在EmpDetails型號

public function genDetails(){ 
    return $this->belongsTo('App\GenDetails'); 
} 

這裏是GenDetails和EmpDetails模型之間一對一的關係。所以請從laravel documentation瞭解更多關於雄辯關係的內容。

+0

不,我的集合有嵌套的列,這就是問題 –

0

GenDetail模式將這個關係

public function empDetails(){ 
    return $this->hasMany('App\EmpDetails','emp_id','personal_details.emp_id'); 
} 

我認爲這種關係將挑釁爲你工作。