Prisma-client-js: Bulk Operations Naming Conflict

Created on 24 Jun 2020  路  3Comments  路  Source: prisma/prisma-client-js

Looking at the bulk transaction docs I have encountered a conflict when there is a model with the name "transaction".

Model

model Transaction {
  balance         String
  base64          String
  deposits        String
  id              Int      @default(autoincrement()) @id
  naration        String
  refNo           String
  transactionDate DateTime
  valueDate       DateTime
  withdrawals     String
  Account         Account  @relation(fields: [id], references: [id])
}

Bulk Transaction API

const write1 = prisma.user.create()
const write2 = prisma.orders.create()
const write3 = prisma.invoices.create()
await prisma.transaction([write1, write2, write3])

Primsa Client API

 prisma.transaction.create(...)
bu2-confirmed kinbug tectypescript

All 3 comments

@williamluke4 Thank you for reporting it 馃檹

We will review what we want to do here soon.

What you could do in the meantime is to adapt your schema.prisma file like:

- model Transaction {
+ model Transaction_ {  // Change name like you want
    balance         String
    base64          String
    deposits        String
    id              Int      @default(autoincrement()) @id
    naration        String
    refNo           String
    transactionDate DateTime
    valueDate       DateTime
    withdrawals     String
    Account         Account  @relation(fields: [id], references: [id])
+
+   @@map(name: "transaction") // the name of your table in your database
}

Execute like:

prisma.transaction_.create(...)

Fixed! We now disallow Transaction and also mention in the error how to fix it.

The error is now a bit more helpful and points to the documentation 馃憤

To learn more about how to rename models, check out https://pris.ly/d/naming-models

Was this page helpful?
0 / 5 - 0 ratings