question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unhandled one-to-one self relation

See original GitHub issue

Bug 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:closed
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Frantsscommented, Aug 10, 2022

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

0reactions
janpiocommented, Aug 10, 2022

We’ve all been there. Thanks anyway!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found