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

PATCH request has stale model relationship data #223

Closed
asugai opened this issue Jan 21, 2023 · 4 comments
Closed

PATCH request has stale model relationship data #223

asugai opened this issue Jan 21, 2023 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@asugai
Copy link

asugai commented Jan 21, 2023

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.

@lindyhopchris
Copy link
Contributor

lindyhopchris commented Jan 22, 2023

@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 minimum-stability in composer.json to dev (keep prefer-stable as true), then run:

composer require laravel-json-api/laravel:^2.5.1 --no-update
composer up laravel-json-api/*

@lindyhopchris lindyhopchris added the bug Something isn't working label Jan 22, 2023
@lindyhopchris lindyhopchris self-assigned this Jan 22, 2023
@asugai
Copy link
Author

asugai commented Jan 22, 2023

@lindyhopchris - confirmed this fix works! Thank you for the quick turn around

@asugai asugai closed this as completed Jan 22, 2023
@asugai asugai reopened this Jan 22, 2023
@lindyhopchris
Copy link
Contributor

Great, thanks for confirming. I'll hopefully be able to tag this evening.

@lindyhopchris
Copy link
Contributor

Tagged in 2.5.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants