PrismaP
Prisma2y ago
2 replies
SpicyJungle

Typescript one to many relation

I'm trying to create a record like this:
          await db.limits.create({
            data: {
              ...limit,
              id: undefined,
              trimorders: allTrimorders
            },
          });

However, typescript complains about the trimorders field:
Type '{ id: number; ticker: string; price: number; dir: string; shares: number; userid: number; }[]' is not assignable to type 'TrimOrdersUncheckedCreateNestedManyWithoutLimitInput | TrimOrdersCreateNestedManyWithoutLimitInput | undefined'.

These are the schemas:
model limits {
  ticker     String
  price      Float
  stoploss   Float?
  takeprofit Float?
  id         Int    @id @default(autoincrement())
  userid     Int
  amount     Int
  style      String
  dir        String
  type       String

  trimorders TrimOrders[]
}


model TrimOrders {
  id     Int    @id @default(autoincrement())
  ticker String
  price  Float
  dir    String
  shares Int
  userid Int

  user users @relation(fields: [userid], references: [id])
  limit limits? @relation(fields: [id], references: [id])
}
Was this page helpful?