Skip to content

Argument ID is missing from createManyAndReturn api #1576

@Tsimopak

Description

@Tsimopak

I have the following models:

model Profile {
  id Int @id @default(autoincrement())
  name String
  items Item[]
  type String
  @@delegate(type)
}

model GoldProfile extends Profile {
  ticket Int
}

model Item {
  id Int @id @default(autoincrement())
  profileId Int
  profile Profile @relation(fields: [profileId], references: [id])
  type String
  @@delegate(type)
}

model GoldItem extends Item {
  inventory Boolean
}

And when I try to create multiple goldItem with the api of createManyAndReturn i get an error that i must profile an id from some reason, even though the id should have a default of auto increment:

  const profile = await db.goldProfile.create({
    data: {
      name: "hello",
      ticket: 5
    }
  })

  const result = await db.goldItem.createManyAndReturn({
    data: [
      {
        profileId: profile.id,
        inventory: true
      },
      {
        profileId: profile.id,
        inventory: true
      }
    ]
  })

I get the following error:

Argument `id` is missing.
    at main (/index.ts:18:36) {
  name: 'PrismaClientValidationError',
  clientVersion: '5.16.2',
  internalStack: 'PrismaClientValidationError: \n' +
    'Invalid `prisma.goldItem.createManyAndReturn()` invocation:\n' +
    '\n' +
    '{\n' +
    '  data: [\n' +
    '    {\n' +
    '      profileId: 1,\n' +
    '      inventory: true\n' +
    '    },\n' +
    '    {\n' +
    '      profileId: 1,\n' +
    '      inventory: true\n' +
    '    }\n' +
    '  ]\n' +
    '}\n' +
    '\n' +
    'Argument `id` is missing.\n' +
    '    at Sn (node_modules/@prisma/client/runtime/library.js:115:7526)\n' +
    '    at _n.handleRequestError (node_modules/@prisma/client/runtime/library.js:122:6570)\n' +
    '    at _n.handleAndLogRequestError (node_modules/@prisma/client/runtime/library.js:122:6235)\n' +
    '    at _n.request (node_modules/@prisma/client/runtime/library.js:122:5919)\n' +
    '    at async l (/node_modules/@prisma/client/runtime/library.js:131:9116)'

Config:

  "devDependencies": {
    "prisma": "^5.16.2",
    "typescript": "^5.5.3",
    "zenstack": "^2.2.4"
  },
  "dependencies": {
    "@prisma/client": "^5.16.2",
    "@zenstackhq/runtime": "^2.2.4"
  }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions