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

Merged
merged 2 commits into from
May 25, 2018

Conversation

beamjet
Copy link
Contributor

@beamjet 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
Copy link
Contributor

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

also, probably needs to go to 5.7

Copy link
Contributor

@tillkruss tillkruss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use filter() without a callback.

@beamjet
Copy link
Contributor Author

beamjet commented May 25, 2018

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

@beamjet
Copy link
Contributor Author

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
@GrahamCampbell GrahamCampbell changed the title Remove null relationships in loadMorph before grouped by class name. [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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants