I am using one to one relationship. My model code is:
public function training_type()
{
return $this->hasone('App\Training_type','id','type');
}
but the parameter "id" is within an array, i tried with following code but not working:
public function training_type()
{
return $this->hasone('App\Training_type','types.id','type');
}
anyone give me good suggession.
Training_type table structure is,
"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")
}
another table structure is,
{
"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"
}
The common practice of passing foreign_key to a relationship is :
The foreign_key is from the table which you want to link.