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.6] Remove null relationships in loadMorph before grouped by class name #24322

Merged
merged 2 commits into from May 25, 2018

Conversation

Projects
None yet
4 participants
@beamjet
Contributor

beamjet commented May 25, 2018

Relationship model may be null when using with() to eager load them, which will cause error in loadMorph() because of the usage of get_class().
So, remove null relationships before group them by class name seems reasonable.

@browner12

This comment has been minimized.

Contributor

browner12 commented May 25, 2018

could you please provide a more thorough description and use case of what this fixes?

also, probably needs to go to 5.7

@tillkruss

Please use filter() without a callback.

@beamjet

This comment has been minimized.

Contributor

beamjet commented May 25, 2018

@tillkruss Thanks for your review. Use filter() without a callback is just much more concise.

@beamjet

This comment has been minimized.

Contributor

beamjet commented May 25, 2018

@browner12 Here is a example:

$notifications = Auth::user()->notifications()
            ->with('subject')
            ->get()
            ->loadMorph('subject', [
                EventInvite::class => 'event',
                GroupPhotoUpload::class => 'group',
                GroupPost::class => 'group',
                PostLike::class => 'post',
            ]);

In this case, subject relationship of notifications are eager-loaded. But some notifications may have no subject relationship and subject model will be null in this case, which will cause error in loadMorph because it passes null to get_class().

@taylorotwell taylorotwell merged commit 3976a43 into laravel:5.6 May 25, 2018

2 checks passed

continuous-integration/styleci/pr The analysis has passed
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@GrahamCampbell GrahamCampbell changed the title from Remove null relationships in loadMorph before grouped by class name. to [5.6] Remove null relationships in loadMorph before grouped by class name May 26, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment