Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.5] Fix getQualifiedParentKey on BelongsToMany #21128

Merged
merged 3 commits into from
Sep 11, 2017

Conversation

Upperfoot
Copy link
Contributor

This is a continuation of the fixes from #21044

Example Code:

// Contained within TemporaryProfile
public function services()
{
    return $this->belongsToMany(Service::class, 'user_profile_services', 'user_id', 'service_id', 'user_id');
}

//Query
TemporaryProfile::has('services')

The services belongsToMany relation has a parentKey specified as user_id, the below SQL query shows that it still wants to use user_temporary_profiles.id as opposed to user_temporary_profiles.user_id

select * from user_temporary_profiles where exists (select * from services inner join user_profile_services on services.id = user_profile_services.service_id where user_temporary_profiles.id = user_profile_services.user_id)

select * from user_temporary_profiles where exists (select * from services inner join user_profile_services on services.id = user_profile_services.service_id where user_temporary_profiles.user_id = user_profile_services.user_id)

Without this fix, queries using any of the has methods will return incorrect results as the query is trying to make use of the default getQualifiedKeyName on the parent (See https://github.com/laravel/framework/blob/5.5/src/Illuminate/Database/Eloquent/Relations/Relation.php#L262)

@taylorotwell taylorotwell merged commit fef63bc into laravel:5.5 Sep 11, 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.

None yet

3 participants