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.7] Prevent unnecessary relationship queries #26992

merged 1 commit into from Dec 29, 2018


None yet
4 participants
Copy link

staudenmeir commented Dec 29, 2018

Prevents unnecessary queries when lazy loading empty relationships:

(new Post(['user_id' => null]))->user; // null
(new User)->posts;                     // []

MorphTo::getResults() is now handled by BelongsTo::getResults() (#8586).

This does not apply to custom relationship queries like (new User)->posts()->get().

I don't think we need additional tests for this. There are plenty of tests that verify relationship queries.

Fixes #25214, #24241, #20616 and laravel/ideas#748.

Copy link

brunogaspar left a comment

Good one!

@taylorotwell taylorotwell merged commit 1aa49b9 into laravel:5.7 Dec 29, 2018

2 checks passed

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

@staudenmeir staudenmeir deleted the staudenmeir:relation-queries branch Dec 29, 2018

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