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

Fix issue with model relations being lost after refresh in getExample… #901

Merged

Conversation

PrinceChoco
Copy link
Contributor

Description :

This PR addresses an issue in the getExampleModelFromFactoryCreate function, where model relations were being loaded before calling refresh(). This caused the loaded relations to be cleared when the model was refreshed, resulting in the loss of relation data.

Example :

In a case like this:

#[ResponseFromApiResource(UserResponse::class, User::class, with: ['job.agency'])]

The agency relation would be cleared by the refresh(), even though it is part of the relations to be loaded. The loading works, but the refresh wipes out the agency relation. With this fix, this issue is resolved.

Changes :

Moved the refresh() call to occur before load() in getExampleModelFromFactoryCreate, ensuring that relations are loaded after the model has been refreshed, preserving the relation data.
This fix will prevent relations from being lost after a model refresh and ensure proper loading of related models.

Let me know if you need further adjustments !

@shalvah shalvah merged commit 3aa44f8 into knuckleswtf:master Oct 18, 2024
6 checks passed
@PrinceChoco PrinceChoco deleted the fix/model-refresh-before-load branch October 19, 2024 04:45
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