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

[8.x] Stop throwing LazyLoadingViolationException for recently created model instances #41549

Merged
merged 5 commits into from Mar 18, 2022

Conversation

rogatty
Copy link
Contributor

@rogatty rogatty commented Mar 18, 2022

Fixes #41420. I think the issue describes the problem and the solution pretty well.

In addition, I had to make a change in Model::handleLazyLoadingViolationUsing which now accepts null, so tests can reset the state. Class property was already nullable so I think it's a good step anyway:

/**
* The callback that is responsible for handling lazy loading violations.
*
* @var callable|null
*/
protected static $lazyLoadingViolationCallback;

At first, I was surprised that new tests were passing without any changes in the code. Then I figured out that only a local public $preventsLazyLoading = true; causes the issue, while global Model::preventLazyLoading() does not. It seems the latter one doesn't trigger the check when using make() or create(). I'd prefer not to dive into this topic now, thus the new class in tests.

@driesvints driesvints changed the title Stop throwing LazyLoadingViolationException for recently created model instances [8.x] Stop throwing LazyLoadingViolationException for recently created model instances Mar 18, 2022
@taylorotwell taylorotwell merged commit 888947c into laravel:8.x Mar 18, 2022
@rogatty rogatty deleted the fix-handle-lazy-loading-violation branch March 18, 2022 14:20
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.

handleLazyLoadingViolation shouldn't throw for newly created model instances
2 participants