You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When doing patchEntity, the value is correctly updated/saved when changed, but jsonTypeField is always marked as dirty.
So even if you don't do any updates, the $entity->isDirty('jsonTypeField') is always true.
What I expected to happen
The patchEntity do a deep array comparison to detect changes because the field value is array and/or because the field type is json.
The expected behavior might need tweaking, especially due to double nature of json tyle field, as you might want to edit each field sep.
I probably going to open PR later, but first I would like to open discussion especially what to check for, as I know that we also have relations to other models that that are also represented as arrays. Also that array could be modified directly without patchEntity that in turn would potentially not flag those changes as dirty and not save them.
CakePHP Version
5.1.2
PHP Version
8.3.14
The text was updated successfully, but these errors were encountered:
When doing patchEntity, the value is correctly updated/saved when changed, but jsonTypeField is always marked as dirty.
So even if you don't do any updates, the $entity->isDirty('jsonTypeField') is always true.
Does the request data contain the jsonTypeField data each time? If so it is 'changing' and the ORM is not currently able to look inside arbitrary structured data and locate differences.
I've moved this issue to enhancment as deep field difference detection isn't a current feature.
Does the request data contain the jsonTypeField data each time?
The data is structured mostly the same between rows, but is different in different tables/fields.
Some are 2 level deep (yes, EAV or shadow table strategy could be used on those), some are 10 level deep.
So I was thinking of making it decoded as array for "ease of access" from code, but if used with helpers ten to just encode the whole array as json on frontend. As the json handling is a nice feature to have it automatically json_decoded, it is now a pain to use in forms where you want to show/forward/handle raw json.
I've moved this issue to enhancement as deep field difference detection isn't a current feature
Totally agreed, json type field is already an edge-case in itself :) My thinking was more about - if there would be a room to merge such feature if provided?
Something to brainstorm if people would be interested and discuss of potential caveats :)
Description
Related to #17886
patchEntity -> isDirty always true for mysql/sqlite with json type fields
What I have
Table with
jsonTypeField
field of typejson
that is automatically converted to array on read.What happens
When doing patchEntity, the value is correctly updated/saved when changed, but jsonTypeField is always marked as dirty.
So even if you don't do any updates, the
$entity->isDirty('jsonTypeField')
is always true.What I expected to happen
The patchEntity do a deep array comparison to detect changes because the field value is array and/or because the field type is json.
The expected behavior might need tweaking, especially due to double nature of json tyle field, as you might want to edit each field sep.
What I have done to mitigate this issue locally
Externally override table using trait:
I probably going to open PR later, but first I would like to open discussion especially what to check for, as I know that we also have relations to other models that that are also represented as arrays. Also that array could be modified directly without patchEntity that in turn would potentially not flag those changes as dirty and not save them.
CakePHP Version
5.1.2
PHP Version
8.3.14
The text was updated successfully, but these errors were encountered: