Skip to content

How to use with explicit many-to-many models (error in Edit view due to Input) #32

@bennettrogers

Description

@bennettrogers

My schema has a few models that are related via many-to-many relations. I'm using the explicit form of the relation in my prisma schema by defining the intermediate model exactly as described in the prisma docs.

As requested in the docs for ra-data-prisma, I'm calling addCrudResolvers on all 3 models (both sides of the relation and the intermediate model).

On the frontend, I'm also defining resources for all 3 models. My issues start when trying to build out the Edit page for the intermediate model. The List view works fine, but when trying to show the Edit view I'm getting a graphql error that says Error: Variable "$where" got invalid value "MODEL_ID" at "where.id"; Expected type StringFilter to be an object. This happens with both the EditGuesser and when trying to define a basic SimpleForm with only a single TextField for the id. (MODEL_ID actually shows up as the string id of the instance it's trying to fetch).

It seems that the Input type expected in the Edit view for the intermediate model is different from the Input type expected by other Edit views, including those for my one-to-many relations. The intermediate model is looking for a ${typeName}WhereInput, whereas the other models are looking for a ${typeName}WhereUniqueInput. This is causing the error since the dataProvider is passing just the id for both Inputs, but ${typeName}WhereInput seems to want a StringFilter.

Sorry for the long explanation. I'm not even sure this is the right package to be creating the issue for. If the explanation isn't clear, I'd be happy to try to create a minimal test repo that demonstrates the issue.

Thank you again for your help.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions