codeledge / ra-tools

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

extractWhere is incorrectly identifying enum types as a string #78

Closed PaulSinghDev closed 7 months ago

PaulSinghDev commented 7 months ago

I have encountered a situation where an enum is incorrectly being as a string and, as such, the query to getList is being populated with a contains field which is causing an error to throw.

Looking a the code it seems as though the plugin is iterating over the keys in the filter which is passed via param and looking to see if the column ends with _enum I am not sure if this is the result of old behaviour or not but, when I inspect the value passed to the filter it is not appending the field type to the column name and, as such, the value is being treated as a string.

I've solved this in my resource handler with a bit of jugaad but it would be good to see this resolved:

    if (
      body.resource === "trend" &&
      body.params?.filter?.peak_month &&
    ) {
      body.params.filter.peak_month = undefined;
      getList.where.peak_month = body.params?.filter?.peak_month as Month;
    }
ogroppo commented 7 months ago

Hi Paul, yes for enum you'll need to append _enum at the end of the field name (i.e. source prop) as per examples in readme:

<SelectInput
        label="Status"
        choices={...}
        source={"status_enum"}
      />,
ogroppo commented 7 months ago

I will close this issue, as there is currently no way to know if a string is an enum or not unless the schema is inspected, which is out of scope of this package