I have two tables, User
and Relationship
. The tables are used to store a parent child relationship. I am using Postgres
// schema.sql
CREATE TABLE "public"."Relationships" (
id SERIAL PRIMARY KEY NOT NULL,
parent_id INT NOT NULL,
FOREIGN KEY (parent_id) REFERENCES "User" (id),
child_id INT NOT NULL,
FOREIGN KEY (child_id) REFERENCES "User" (id)
)
CREATE TABLE "public"."User" (
id SERIAL PRIMARY KEY NOT NULL,
name VARCHAR(128) NOT NULL,
email VARCHAR(128) UNIQUE,
password VARCHAR(128) NOT NULL,
isChild BOOLEAN NOT NULL DEFAULT false
created_at TIMESTAMP NOT NULL DEFAULT NOW();
);
When I run npx prisma introspect
the following is returned in the schema.prisma
file.
// schema.prisma
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model Relationships {
child_id Int
id Int @default(autoincrement()) @id
parent_id Int
User_Relationships_child_idToUser User @relation("Relationships_child_idToUser", fields: [child_id], references: [id])
User_Relationships_parent_idToUser User @relation("Relationships_parent_idToUser", fields: [parent_id], references: [id])
}
model User {
created_at DateTime @default(now())
email String? @unique
id Int @default(autoincrement()) @id
ischild Boolean @default(false)
name String?
password String
Relationships_Relationships_child_idToUser Relationships[] @relation("Relationships_child_idToUser")
Relationships_Relationships_parent_idToUser Relationships[] @relation("Relationships_parent_idToUser")
}
I dont understand what User_Relationships_child_idToUser
and User_Relationships_parent_idToUser
are and why they are not just the simple syntax that appears for foreign keys in the Prisma docs tutorial.