Skip to content

type check error when creating record for implicit many-to-many model #2534

@jiashengguo

Description

@jiashengguo
model Post {
    id         Int        @id @default(autoincrement())
    title      String
    categories Category[]
}
model Category {
    id    Int    @id @default(autoincrement())
    name  String
    posts Post[]
}

For the above schema, when creating the data, type checker shows error:

Property 'id' is missing in type '{ name: string; }' but required in type 'Omit<CreateWithFKInput<SchemaType, "Category", { dialect: SqliteDialect; }>, "posts">'.ts(2322)
  const post = await db.post.create({
    data: {
      title: "How to become a butterfly",
      categories: {
        create: [{ name: "Life" }, { name: "Transformation" }],
      },
    },
  });

It shows the same error even without creating nested record:

await db.post.create({
    data: {
      title: "How to become a butterfly",
    },
  });

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions