Unhandled one-to-one self relation
See original GitHub issueBug description
When trying to declare a ono-to-one self-relation, as specified by the docs I’m getting the following error:
Error validating model "ArrayValidation": Wrongly named relation detected. The fields `itemValidation` and `parentValidation` in model `ArrayValidation` both use the same relation name. Please provide different relation names for them through `@relation(<name>).
Which in turn causes weird auto-complete once I save the file.
How to reproduce
The following prisma file can be used to reproduce the error
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}
model SelfRelation {
id String @id @default(cuid())
selfRelationId String
selfRelation SelfRelation? @relation("SomeSelfRelation", fields: [selfRelationId], references: [id])
theOtherSideOfTheRelation SelfRelation? @relation("SomeSelfRelation")
}
Expected behavior
The extension recognizes the relation as valid
Prisma information
Environment & setup
- OS: MacOS
- Editor: VSCode
- Editor version: 1.7.0
- Extension version: 4.2.0
Issue Analytics
- State:
- Created a year ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
One-to-one, self-referencing, bi-directional relationship
Have you found a solution for this? I want to do the same thing but I separated the relation with 2 oneToOne self-referencing...
Read more >Self-referencing OneToOne with STI · Issue #1140 · mikro-orm ...
It seems that Mikro sees 2 sides? Expected behavior. That i can declare a nullable self-referencing relationship on the base "entity" here that ......
Read more >Strange behaviour with self referencing one-to-one ...
I am having a system where users can register for events. Each registration entity has a one-to-one self referencing relationship called "partner" -...
Read more >Association Mapping - Doctrine Object Relational Mapper ...
Doctrine Object Relational Mapper Documentation: Association Mapping. ... You can define a self-referencing one-to-one relationships like below.
Read more >Model Relationships in Django REST Framework - Corgibytes
In Django, we represent these relationships as fields on models, using ForeignKey , OneToOneField , and ManyToManyField to represent them.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

The model I was working on had another error, which was obfuscating this one. I then created that example and didn’t realize it was actually a different error. I should have not filed a bug at the end of my work day haha
We’ve all been there. Thanks anyway!