hello, i am trying to make a on to one self-relati...
# orm-help
d
hello, i am trying to make a on to one self-relation but not working exactly as I want
Copy code
model Element {
    id        String   @id @db.VarChar(255)
    element   String   @db.VarChar(255)
    parentId  String?  @db.VarChar(255)
    required  Boolean  @db.Boolean
    createdAt DateTime @default(now()) @db.Timestamptz
    updatedAt DateTime @updatedAt @db.Timestamptz

    parent PoomElement? @relation("ParentElement", fields: [parentId], references: [id])
}
after I save the auto format of prisma adds another relation which I dont want
Element Element[] @relation("ParentElement")
is that above relation necassary? In the docs I see its not required: https://www.prisma.io/docs/concepts/components/prisma-schema/relations#one-to-one-self-relations
r
You can remove the array and it should work fine:
Copy code
model Element {
  id        String   @id @db.VarChar(255)
  element   String   @db.VarChar(255)
  required  Boolean  @db.Boolean
  createdAt DateTime @default(now()) @db.Timestamptz
  updatedAt DateTime @updatedAt @db.Timestamptz
  parent    Element? @relation("ElementToElement", fields: [elementId], references: [id])
  Element   Element? @relation("ElementToElement")
  elementId String?  @db.VarChar(255)
}