Skip to content

Conversation

@maxhumme
Copy link
Contributor

Hello,

When I use a HasManyThrough relation with a custom localKey in a Eloquent whereHas statement, it returns 0 results. This is because in the HasManyThrough class the primary key of the farParent model is used, instead of the in the relation defined custom key of that model.

To fix this, we go from

public function getExistenceCompareKey()
{
    return $this->farParent->getQualifiedKeyName();
}

to

public function getExistenceCompareKey()
{
    return $this->farParent->getTable().'.'.$this->localKey;
}

Test included in the commit.

@GrahamCampbell GrahamCampbell changed the title Fix HasManyThrough relation with custom keys when used in whereHas [5.5] Fix HasManyThrough relation with custom keys when used in whereHas Nov 14, 2017
@taylorotwell taylorotwell merged commit 2227971 into laravel:5.5 Nov 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants