Is it possible to have a hasMany relationship in two columns?
My table has two columns, user_id and related_user_id .
I want my relationship to match any of the columns.
In my model I have
public function userRelations() { return $this->hasMany('App\UserRelation'); }
Why the request is executed: select * from user_relations where user_relations.user_id in ('17', '18') .
I need to execute the following query:
select * from user_relations where user_relations.user_id = 17 OR user_relations.related_user_id = 17
EDIT:
I am using active loading, and I think this will affect how it works.
$cause = Cause::with('donations.user.userRelations')->where('active', '=', 1)->first();
source share