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.2] Add loadOnly() method to only load specified relations #14090

Closed
wants to merge 3 commits into from
Closed

[5.2] Add loadOnly() method to only load specified relations #14090

wants to merge 3 commits into from

Conversation

JayBizzle
Copy link
Contributor

@JayBizzle JayBizzle commented Jun 21, 2016

Following on from #14031

Say we have three Models User, UserData and UserComments.

User has a userData relationship that we always want to eager load, so we define that in the $with attribute. It also has a userComments relationship that we eager load as required.

Now, consider this...

$users = User::without('userData')->get();

$users->load('userComments');

This will eager load the specified userComments relationship AND also load the userData relationship. This is perhaps a little confusing, because that is not what we wanted to do.

Not sure if this is expected behaviour, or an oversight in the behaviour of the load() method...current behaviour seems counter intuitive.

To maintain backwards compatibility, I suggest a new method called loadOnly(), which will actually load ONLY the specified relationships.

@taylorotwell
Copy link
Member

Going to hold off on this.

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