我正在使用一对一的关系。我的模型代码是:
public function training_type()
{
return $this->hasone('App\Training_type','id','type');
}
但参数“id”在一个数组中,我尝试使用以下代码但不工作:
public function training_type()
{
return $this->hasone('App\Training_type','types.id','type');
}
任何人都给我很好的建议。
Training_type 表结构是,
"company_id": "company1",
"types": [
{
"id": "1",
"name": "Generic"
},
{
"id": "2",
"name": "Compensation and Benefits"
},
{
"id": "3",
"name": "Labor and Employment Law"
}
],
"updated_at": ISODate("2017-08-10T10:24:40.000+05:30")
}
另一个表结构是,
{
"company_id": "company1",
"title": "Fire Extinguisher\t",
"content_type": "",
"links": [
{
"link": ""
},
{
"link": ""
}
],
"updated_at": ISODate("2017-08-10T10:24:40.000+05:30"),
"type": "1"
}