Yunbo
06/22/2022, 2:27 AM@relation("accountsTojobs_account_id") in schema.prisma )
2. account has one create_job_id ( @relation("accounts_create_job_idTojobs", fields: [create_job_id], references: [id]) in schema.prisma )
I'm trying to create a job -> an account
according to prisma client relation queries documentation,
when i create a job and include account ( code below ), i shouldn't have to specify create_job_id in account object since i won't know the id until its creation.
but the vs code throws an error saying create_job_id is required field.
Error Message
Type '{ email: string; }' is not assignable to type 'Without<AccountUncheckedCreateWithoutJobsInput, AccountCreateWithoutJobsInput> & AccountCreateWithoutJobsInput'.
my gut tells me i'm missing something on schema file.
Could anyone take a look at this and give me some feedback?
Thanks in advance,
schema.prisma
model Account {
id Int @id @default(autoincrement())
email String
create_job_id Int
create_account_job Job @relation("accounts_create_job_idTojobs", fields: [create_job_id], references: [id])
jobs Job[] @relation("accountsTojobs_account_id")
@@map("accounts")
}
model Job {
id Int @id @default(autoincrement())
title String?
status String @default("pending")
account_id Int?
account Account? @relation("accountsTojobs_account_id", fields: [account_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "jobs_account_id_fkey")
accounts Account[] @relation("accounts_create_job_idTojobs")
@@map("jobs")
}
code :
account create object throws an error unless i add create_job_id which i won't know until parent(job) is created
prisma.job.create({
data: {
title: `Create an account`,
status: `PENDING`,
account: {
create: {
email: `<mailto:hello@test.com|hello@test.com>`,
// create_job_id : ??? i shouldn't have to add this line
},
},
},
});Harsh Singh
06/22/2022, 3:05 AMcreate_job_id isn't an index 😄Yunbo
06/22/2022, 5:38 PMaccount: {
create: {
email: `<mailto:hello@test.com|hello@test.com>`,
// create_job_id : ??? i shouldn't have to add this line
},
},
to
accounts: {
create: [{
email: `<mailto:hello@test.com|hello@test.com>`,
// now i don't need to add create_job_id
}],
},Harsh Singh
06/22/2022, 6:30 PMYunbo
06/22/2022, 11:53 PM