Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

pranayb2773's avatar

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);
    }

0 likes
0 replies

Please or to participate in this conversation.