Skip to content

TRPC results in runtime error when creating a model inherited from a delegate model #1608

@ymc9

Description

@ymc9
model Content  {
  id          Int      @id @default(autoincrement())
  user       User @relation(fields: [userId], references: [id])
  userId    String @default(auth().id)

  contentType String

  @@delegate(contentType)

  @@allow('all', true)
}


model Post extends  Content {
  title String
}
const create = trpc.post.create.useMutation();

const onClick = async () => {
        if (user?.id) {
            await create.mutateAsync({
                data: {
                    title: 'title post',
                },
            });
        }
    };
TRPCClientError: [
  {
    "code": "invalid_union",
    "unionErrors": [
      {
        "issues": [
          {
            "code": "invalid_type",
            "expected": "string",
            "received": "undefined",
            "path": [
              "data",
              "contentType"
            ],
            "message": "Required"
          }
        ],
        "name": "ZodError"
      },
      {
        "issues": [
          {
            "code": "invalid_type",
            "expected": "string",
            "received": "undefined",
            "path": [
              "data",
              "contentType"
            ],
            "message": "Required"
          }
        ],
        "name": "ZodError"
      }
    ],
    "path": [
      "data"
    ],
    "message": "Invalid input"
  }
]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions