codeledge / ra-tools

React Admin Tools, namely the Prisma Data Adapter
66 stars 19 forks source link

Not Updating JSON Field #12

Closed fauh45 closed 2 years ago

fauh45 commented 2 years ago

Currently I'm developing apps that require one of the field to be the type of JSON. (Prisma Reference)

The problem is every time the data is updated to the database, the JSON field would not be updated. I've done some digging and found this code at the file updateHandler.ts.

      if (!isObject(value) && !options?.skipFields?.includes(key))
        fields[key] = value;

      return fields;

Link to code

I think the problem is, that this library thinks the JSON field is actually a relation to another model, so it is skipped. I think there should be a way to differentiate it, or at least have a configuration to allow a particular field on a model to be updated.

martin-fv commented 2 years ago

Yes currently JSON isn't supported, thanks for reporting it. We will look into it.

If you would like to raise a PR, we will merge it timely!

fauh45 commented 2 years ago

I did see you guys have skipFields options for updateHandler, could I just add that configuration in the default handler alongside the delete options that's already there?

martin-fv commented 2 years ago

This question would be for @ogroppo , but go ahead and see if it works, you might see similar cases in the other data providers.

fauh45 commented 2 years ago

For sure, currently testing it right now, I'll let you guys know my solution.

fauh45 commented 2 years ago

Opened a new PR ( #14 ) to fix my use cases, the solution is simple, but might not be general enough for all of the use cases.