SpicyJungle
SpicyJungle
Explore posts from servers
PPrisma
Created by SpicyJungle on 7/9/2024 in #help-and-questions
Typescript one to many relation
I'm trying to create a record like this:
await db.limits.create({
data: {
...limit,
id: undefined,
trimorders: allTrimorders
},
});
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])
}
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])
}
3 replies