hi all, can anyone tell me if it’s possible to cre...
# orm-help
a
hi all, can anyone tell me if it’s possible to create a deeply nested entities? I’m trying to do something like seeding a user with a post and several comments with replies:
Copy code
await 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:
Copy code
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")
}
r
@alechko 👋 I don’t think that’s possible as you’re creating the comments inside the comment and not the post. At the moment, only a single level is supported.
a
thank you for the reply! I feared that it’s not possible 🙂 could be a handy feature though…
r
I would suggest creating one here 🙂
a
thank you, I will do that
🙌 1