alechko
11/18/2021, 6:33 AMawait prisma.user.create({
data: {
email: faker.internet.email(),
posts: {
create: {
title: faker.lorem.sentence(10),
comments: {
create: [
{
body: faker.lorem.paragraph(10),
children: {
create: [ <--- THIS FAILS TO INHERIT THE POST
{
body: faker.lorem.paragraph(10),
}
]
},
},
],
},
},
},
},
});
So the children
section fails because the Comment entity has a postId
field, and it’s working (inheriting the post) for the parent comment but not for children comments.
my comment model looks like this:
model Comment {
id String @id() @default(uuid()) @db.Uuid
body String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
deletedAt DateTime?
user User? @relation(fields: [userId], references: [id], onDelete: SetNull)
userId String? @db.Uuid
post Post @relation(fields: [postId], references: [id], onDelete: Cascade)
postId String @db.Uuid
parent Comment? @relation("CommentParent", fields: [parentId], references: [id])
parentId String? @db.Uuid
children Comment[] @relation("CommentParent")
}
Ryan
11/18/2021, 7:35 AMalechko
11/18/2021, 7:39 AMRyan
11/18/2021, 7:44 AMalechko
11/18/2021, 7:46 AM