sagar lama
08/22/2022, 8:53 AMmodel Product {
id Int @id @default(autoincrement())
name String?
fees Fee[] @relation("fees")
default_fee Fee? @relation("default_fee")
}
model Fee {
id Int @id @default(autoincrement())
total Float @default(0)
product_id Int
product Product @relation(name: "fees", fields: [product_id], references: [id], onDelete: Cascade)
defaultable Product? @relation(name: "default_fee", fields: [defaultable_id], references: [id])
defaultable_id Int? @unique
}
While fetching its works like expected.
However while creating product with nested relations like this:
const product = await this.prisma.product.create({
data: {
...data,
default_fee: {
create: {
// asks for product id
total: 500,
},
},
},
});
It asks me for product id. But it doesn't make sense to pass product_id as I wouldn't have the product id at that point.
I know I can make it work by breaking the query down, but nested create doesnot seem to work for disambiguating relations. I'm curious wether it's issue on prisma or I'm missing something here
Repo Link: https://github.com/sagarPakhrin/prisma-disambiguating-relations/blob/master/src/app.service.tsnikolasburk
const fee = await prisma.fee.create({
data: {
total: 100,
product: {
create: {
name: "My Product"
}
}
}
})
Or does this problem also persist when doing it this way?sagar lama
08/22/2022, 10:55 AMnikolasburk
$queryRaw
unfortunately 😕sagar lama
08/22/2022, 11:03 AMconst product = await this.prisma.product.create({
data: {
name: 'product1',
},
});
const fee = await this.prisma.fee.create({
data: {
total: 100,
defaultable_id: product.id,
product: {
connect: {
id: product.id,
},
},
},
});
But still it gives me any error saying
Types of property 'defaultable_id' are incompatible.
Type 'number' is not assignable to type 'never'
I'll be opening an issueBastien Etienne
08/23/2022, 9:16 AMBastien Etienne
08/23/2022, 9:18 AMawait prisma.cibest_role.create({
data: {
name: "super admin",
description: "Role qui à tous les droits",
feature: {
create: [
{
service_name: "role",
create: true,
read: true,
update: true,
delete: true,
},
{
service_name: "authentication",
create: true,
read: true,
update: true,
delete: true,
},
],
},
},
});
await prisma.cibest_user.create({
data: {
email: "<mailto:super-admin@cibest.com|super-admin@cibest.com>",
first_name: "John",
last_name: "Doe",
password: hash,
avatar: "<https://robohash.org/john> doe",
cibest_users_roles: {
create: { cibest_role: { connect: { name: "super admin" } } },
},
},
});
}
Bastien Etienne
08/23/2022, 9:19 AMBastien Etienne
08/23/2022, 9:19 AMmodel cibest_user {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
date_created DateTime @default(now()) @db.Timestamp(6)
first_name String @db.VarChar(64)
last_name String @db.VarChar(64)
email String @unique @db.VarChar(64)
password String @db.VarChar
ldap_account Boolean?
ldap_id String? @db.VarChar
addressId String? @db.Uuid
avatar String?
languageId String? @db.Uuid
address address? @relation(fields: [addressId], references: [id])
language language? @relation(fields: [languageId], references: [id])
cibest_user_agency cibest_user_agency[]
cibest_users_roles cibest_users_roles[]
token token[]
}
Bastien Etienne
08/23/2022, 9:20 AMmodel cibest_users_roles {
cibest_user_id String @db.Uuid
cibest_role_id String @db.Uuid
cibest_role cibest_role @relation(fields: [cibest_role_id], references: [id])
cibest_user cibest_user @relation(fields: [cibest_user_id], references: [id])
@@id([cibest_role_id, cibest_user_id])
}
Bastien Etienne
08/23/2022, 9:20 AMmodel cibest_role {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
date_created DateTime @default(now()) @db.Timestamp(6)
name String @unique @db.VarChar(32)
description String
iconId String? @db.Uuid
icon icon? @relation(fields: [iconId], references: [id])
cibest_users_roles cibest_users_roles[]
feature feature[]
}
Bastien Etienne
08/23/2022, 9:20 AM