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.

Improve self relations example

See original GitHub issue

Bug description

Example in the docs suggests that self relations may be optional, but the types require the relation.

Am I missing something with the spec here? 😅

Hope the reproduction helps! 🙂

How to reproduce

datasource db {
    provider = "mysql"
    url      = env("DATABASE_URL")
}

generator client {
    provider = "prisma-client-js"
}

model User {
  id       Int      @id @default(autoincrement())
  name     String?
  husband  User      @relation("MarriagePartners", fields: [id], references: [id])
  wife     User?     @relation("MarriagePartners")
}
import { PrismaClient } from '@prisma/client'

const client = new PrismaClient()

client.user.create({
    data: {
        name: "George"
    }
})

https://github.com/maticzav/prisma-client--selfrelation-bug-reproduction

Expected behaviour

Create method should have an optional husband field.

Prisma information

Environment & setup

  • OS: Mac OS
  • Database: MySQL
  • Prisma version:
@prisma/cli          : 2.0.0-beta.2
Current platform     : darwin
Query Engine         : query-engine 76857c35ba1e1764dd5473656ecbbb2f739e1822 (at /Users/maticzav/Code/sandbox/prisma-client-self-relation-issue/node_modules/@prisma/cli/query-engine-darwin)
Migration Engine     : migration-engine-cli 76857c35ba1e1764dd5473656ecbbb2f739e1822 (at /Users/maticzav/Code/sandbox/prisma-client-self-relation-issue/node_modules/@prisma/cli/migration-engine-darwin)
Introspection Engine : introspection-core 76857c35ba1e1764dd5473656ecbbb2f739e1822 (at /Users/maticzav/Code/sandbox/prisma-client-self-relation-issue/node_modules/@prisma/cli/introspection-engine-darwin)
  • Node.js version: v12.16.1

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
pantharshit00commented, Apr 24, 2020

@maticzav No, they should not be required. We disallow required self realtions now because you can’t create a root node if they are required.

0reactions
mhwelandercommented, May 25, 2020

👋 Hi folks - the relations example has been updated: https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-schema/relations#self-relations

(It includes example SQL that uses a unique constraint to create a 1-1 self-relation so that you can introspect.)

Thanks for raising the issue! 💚

Read more comments on GitHub >

github_iconTop Results From Across the Web

12 Keys To A Great Self-Relationship, Starting Now
1. Set intention and cultivate awareness. Set the overarching goal, over a span of years, to keep moving toward a good relationship with ......
Read more >
Do You Have a Healthy Relationship with Yourself? Here's ...
A healthy relationship with yourself may help you better cope with life challenges and mental health conditions. It may also improve social ...
Read more >
11 Ways to Improve Your Relationship With Yourself - HuffPost
A few examples of self-love habits could be: thanking yourself for making your bed, going on a weekly date with yourself, spending time...
Read more >
7 Ways to Focus on Yourself - Healthline
Get better acquainted with yourself ... Building a strong self-relationship is a great way to return your focus to yourself. Feeling uncertain about...
Read more >
3 ways to help you be your best self in your relationship |
“Challenge yourself to be helpful, patient, caring and kind,” says Adler. “These are all factors that research indicates make relationships ...
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