Nov 17, 2021
0
Level 6
HasOneThrough Relationship where two foreign keys on same table
I have companies, option_groups and option_values three tables. Where company status, Option Group Id both have foreign keys on Option Value table.
companies(status) ---> option_values(value)
option_groups(id) ---> option_values(option_group_id)
In Company Model, I am fetching status name with HasOne relation. Can this be achieve through HasOneThrough realtion also?.
public function status(): HasOne
{
return $this->hasOne(OptionValue::class, 'value', 'status')
->select(['label', 'value'])
->where('option_group_id', '=', OptionGroup::firstWhere('slug', '=', 'companies_status')->id);
}
Please or to participate in this conversation.