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

Avoid saving casts to DB #24

Open
wants to merge 1 commit into
base: development
Choose a base branch
from

Conversation

danhunsaker
Copy link

When adding a versioned attribute that also has a accessor or cast of some kind, the current code retrieves the accessor/casted version and attempts to store that, instead of the mutated DB-friendly version we would expect. This commit fixes that, by retrieving the value from the raw attributes array, instead of through the virtual property, and thereby skips any accessors/casts.

This issue came up while using this package along with Spatie's translatable models package, and MySQL throwing a fit about not wanting to save the non-JSON'd English translation of a value in a JSON field. This change fixes that issue, and probably many others besides.

When adding a versioned attribute that also has a accessor or cast of some kind, the current code retrieves the _accessor_/_casted_ version and attempts to store that, instead of the _mutated_ DB-friendly version we would expect. This commit fixes that, by retrieving the value from the raw attributes array, instead of through the virtual property, and thereby skips any accessors/casts.
@danhunsaker danhunsaker changed the title Avoid saving mutations to DB Avoid saving casts to DB Dec 27, 2019
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.

1 participant