-
Notifications
You must be signed in to change notification settings - Fork 11k
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
PHP JSON vs MySQL JSON Extra Space Between key:value #46247
Comments
I'm sorry but I'm not sure I see the issue here right now. If you want, you can attempt a PR. Thanks |
Issue is that if one has json colum in database and has [laravel Custom Casts ](https://laravel.com/docs/9.x/eloquent-mutators#custom-casts) and just access attribute isDirty will be true. I have just provided context. |
FYI, I have seen similar issue raised here -> #28029. Kind of a hard issue to solve since MySQL's json format is weird. |
@driesvints I have no issue doing PR. The question is where to or what to do. I have trait that solves it for specific model column. This is not something that most users will not have but... When you do some enterprise apps you need audit and this is killing it. From Usage perspective this is clear laravel bug. When you get json colum that is custom casted you get isDirty as true. Laravel is not causer of this issue, agreed. it is more whole ecosystem of mysql8 and php... One can use text instead of json, but that is big compromise. So maybe if one can steer me in direction how this PR should be implemented in framework, i can do it. My question is more. What is ideal way to deal with this. What options are good one
|
@kerbs-ns I honestly don't know sorry. I don't see a good solution for this. |
FYI, this is how rails solves it... |
We have to extend the database grammer with an json encoder method to be able to emulate the database specific json encoding for mysql as an example. The method should be used in all grammer context instead of |
This approach does not take into account the different ordering of JSON elements that results from the normalization of Mysql's JSON data. But what should work is the recursive calculation of the difference between the original and current data as an associative array with index checking. This is how it works from my point of view: Casts that work with JSON fields must extend the JSON cast class |
This is no longer necessary with the recent commit. |
Description:
When using json as colum type the way mysql works and php we have issue having isDirty even if we just access attribute.
https://stackoverflow.com/questions/72958866/php-json-vs-mysql-json-extra-space-between-keyvalue
Steps To Reproduce:
create migration
$table->json('video')->nullable();
have cast
Asset::class is just json_encode json_decode nothing special.
This is some pseudo solution that is expensive but hides issue under rug
The text was updated successfully, but these errors were encountered: