Improve self relations example
See original GitHub issueBug 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:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top 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 >
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

@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.
👋 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! 💚