Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested createMany with skipDuplicates option is not handled correctly #1162

Closed
ymc9 opened this issue Mar 20, 2024 · 0 comments
Closed

Nested createMany with skipDuplicates option is not handled correctly #1162

ymc9 opened this issue Mar 20, 2024 · 0 comments
Milestone

Comments

@ymc9
Copy link
Member

ymc9 commented Mar 20, 2024

ZModel

model User {
  id String @id @default(cuid())
  companies CompanyUser[]
  @@allow('all', true)
}
            
model Company {
  id String @id @default(cuid())
  users CompanyUser[]
  @@allow('all', true)
}
            
model CompanyUser {
  company Company @relation(fields: [companyId], references: [id], onDelete: Cascade)
  companyId String
  user User @relation(fields: [userId], references: [id], onDelete: Cascade)
  userId String
  @@id([companyId, userId])
  @@allow('all', true)
}

Code

const db = enhance(prisma);
await db.user.create({ data: { id: 'abc' } });
await db.user.create({ data: { id: 'def' } });
await db.company.create({ data: { id: '1', users: { create: { userId: 'abc' } } } });
await db.company.update({
     where: { id: '1' },
     data: {
       users: {
         createMany: {
           data: [{ userId: 'abc' }, { userId: 'def' }],
           skipDuplicates: true,
         },
       },
     },
     include: { users: true },
})

The code should succeed but it results in unique constraint violation error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant