Parent model in child model in Prisma?

Sorry for the confusing title, I'm looking to do something like this:
model Parent {
id String @id @default(cuid())
name String

children Child[]
}

model Child {
id String @id @default(cuid())
name String

parent Parent? @relation(fields: [parentId], references: [id])
parentId String?

subChild Parent // is something like this possible? <<<<
}
model Parent {
id String @id @default(cuid())
name String

children Child[]
}

model Child {
id String @id @default(cuid())
name String

parent Parent? @relation(fields: [parentId], references: [id])
parentId String?

subChild Parent // is something like this possible? <<<<
}
3 Replies
Linus
Linus2y ago
Why does subChild have parent type? It should work just like the relation above, but you need to give the relation a name if you reference the same model multiple times
hyperzone
hyperzoneOP2y ago
i've simplified the example but I need the child to have a child that is essentially a Parent with children that have the same properties as Child
Linus
Linus2y ago
What is not working when making this a relation like the one above then? Also, this might be because its simplified but if this is a tree structure it should only be a node model that references itself i think.
Want results from more Discord servers?
Add your server