return relation in nested write in prisma

I have two models that looks as such:
model Card {
id String @id @default(uuid())
createdAt DateTime @default(now())
title String
tasks Task[]
}

model Task {
id String @id @default(uuid())
createdAt DateTime @default(now())
title String
cardId String
completed Boolean @default(false)
card Card @relation(fields: [cardId], references: [id])
}
model Card {
id String @id @default(uuid())
createdAt DateTime @default(now())
title String
tasks Task[]
}

model Task {
id String @id @default(uuid())
createdAt DateTime @default(now())
title String
cardId String
completed Boolean @default(false)
card Card @relation(fields: [cardId], references: [id])
}
i'm trying to create a task, but in doing so, return the card to which it belongs. i currently have this
const newCard = await ctx.p.task.create({
data: {
title: input.title,
cardId: input.card_id
},
select: {
card: {
include: {
tasks: true
}
}
}
});
const newCard = await ctx.p.task.create({
data: {
title: input.title,
cardId: input.card_id
},
select: {
card: {
include: {
tasks: true
}
}
}
});
but its returning something with the following type:
{
card: Card & {
tasks: Task[];
};
}
{
card: Card & {
tasks: Task[];
};
}
so essentially its giving me the return type that i want, but nested inside of the card property. is there any way around this ?
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server