-
Notifications
You must be signed in to change notification settings - Fork 100
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
JSON columns with array cast are double encoded #43
Comments
unfortunately we just got the bug. can we merge this PR? thanks :) |
Yes, I changed the line locally in the vendor and it worked. |
Just merged this pull request. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When a model has a "JSON array castable field", for example by defining
protected $casts = ['field' => 'array']
, the stored versions will be double JSON encoded. For example, if the original model's column value was{"a": "b"}
, the version'sgetModel()
will have the column value"{\"a\": \"b\"}"
.This happens because when saving a version,
VersionableTrait::versionablePostSave()
usesgetAttributes()
, and when restoring a version,Version::getModel()
usesfill($attributes)
.fill
will do conversions based on$casts
(JSON encoding in this case), butgetAttributes
returns attributes as-is (already JSON-encoded string in this case). To fix this,VersionableTrait::versionablePostSave()
should useattributesToArray()
instead, which would return array castable columns as arrays, so thatfill()
works expectedly.The text was updated successfully, but these errors were encountered: