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

Newly created models don't serialize all attributes #101

Open
KeithTurkowski opened this issue Apr 19, 2023 · 0 comments
Open

Newly created models don't serialize all attributes #101

KeithTurkowski opened this issue Apr 19, 2023 · 0 comments

Comments

@KeithTurkowski
Copy link

I believe that you should check wasRecentlyCreated on models and reload them if it is true before calling attributesToArray.

Currently, because you are using attributesToArray, newly created models will only return attributes that have been modified / updated. This means the attributes list may not be complete, and the next time the model is loaded and modified, then all attributes will be returned with attributesToArray... This will result in the second "version" of the model including the attributes, even if they haven't been modified, and it will appear as if they were changed when doing a diff. I also suspect that it would cause issues when attempting to roll back to the initial version.

My current workaround is to using a create method on the model to do: $model = self::find(self::create()->id) to ensure that the initial version contains the full list of serialized attributes.

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

1 participant