-
Notifications
You must be signed in to change notification settings - Fork 43
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
PATCH request has stale model relationship data #223
Comments
@asugai thanks for opening this issue. could you give the fix a go before I tag it? Obviously remove the controller work-around that you used, then install the next version of this package. To do that, set your composer require laravel-json-api/laravel:^2.5.1 --no-update
composer up laravel-json-api/* |
@lindyhopchris - confirmed this fix works! Thank you for the quick turn around |
Great, thanks for confirming. I'll hopefully be able to tag this evening. |
Tagged in |
Per discussions with @lindyhopchris on Slack:
on a PATCH request, this package serializes the model to its JSON:API representation before validation occurs, so that we can give the validator the current values of anything that hasn't been sent in the request.
This causes the model to cache the relationship in it's pre-patched state so when the model then later gets serialized for the response, it's got stale data in its relationship cache.
The only fix, is to
$model->refresh()
in the updated hook on the controller.If possible, we need to always refresh the model to be sure that the package has non-stale data.
The text was updated successfully, but these errors were encountered: