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

Chaining multiple nested eager loads of relations leads to cleaning up before loaded data. #24764

Closed
humunuk opened this issue Jul 6, 2018 · 4 comments

Comments

@humunuk
Copy link

humunuk commented Jul 6, 2018

  • Laravel Version: 5.4
  • PHP Version: 7.1.18
  • Database Driver & Version: MySQL, 5.7.22

Description:

Im not sure if this is expected behavior or bug.

Loading nested relationships to model in multiple steps deletes / clears up before loaded relations.

Steps To Reproduce:

$model = Model::with('relation.nested1')->first();
$model->load('relation.nested2');

After the second load, nested1 is not anymore eager loaded into $model.

@staudenmeir
Copy link
Contributor

This is the expected behavior (#23027, #24121). What type of relationship is relation in your case?

@humunuk
Copy link
Author

humunuk commented Jul 6, 2018

Ok I went through the issues and see its expected behaviour, thank you very much for responding :)
The first relation is hasMany for Model, it goes 2 levels deep where both has hasMany with the last one being belongsTo

As with other issue creator, i have the same problem that i need to load them dependant on condition

@staudenmeir
Copy link
Contributor

In Laravel 5.6 you can use $model->loadMissing('relation.nested2') (#24166).

Until then, use this:

$model->relation->load('nested2');

@humunuk
Copy link
Author

humunuk commented Jul 6, 2018

thank you so much for the help :), can close this

@themsaid themsaid closed this as completed Jul 9, 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

No branches or pull requests

3 participants