laravel/framework

Querying relations with extra conditions in Eager Loading not working

tisuchi opened this issue · 6 comments

My regular data fetching issue has been solved by this issue.

But when I need to fetch this relationship in eager loading, it always return null.

For example-

public function allMatches()
{
     return $this->hasMany('Match', 'visitant_id')->orWhere('local_id', $this->id);
}

If I need to fetch with() method, its not working.

$team = Team::where('id', 2)->with('allMatches')->first();

your relation is defined wrongly

@Dylan-DPC
Haha. I believe, you didn't read the whole things. Take a look very carefully before submitting your comment again that, @taylorotwell gave this solution here...
#1272

I M NOT WRONG. I just follow him.

its not working.

More details please, what's the laravel version you use?

Closing for lack of activity.

I am using laravel 5.2

@tisuchi For laravel 5.4 or greater, you may use https://github.com/topclaudy/compoships to solve this issue.