Implicit m-n-relations no longer works in v3
See original GitHub issueBug description
TypeScript file generated by the client does not contain m-n-relations.
How to reproduce
- Initialize database with the following query. It came from the documentation.
CREATE TABLE Category (
id SERIAL PRIMARY KEY
);
CREATE TABLE Post (
id SERIAL PRIMARY KEY
);
CREATE TABLE _CategoryToPost (
A SERIAL NOT NULL REFERENCES Category(id) ,
B SERIAL NOT NULL REFERENCES Post(id)
);
CREATE UNIQUE INDEX _CategoryToPost_AB_unique ON _CategoryToPost(A,B);
CREATE INDEX _CategoryToPost_B_index ON _CategoryToPost(B);
- Run
prisma db pull
and it creates the following schema.
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model category {
id Int @id @default(autoincrement())
post post[] @relation("categorytopost")
}
model post {
id Int @id @default(autoincrement())
category category[] @relation("categorytopost")
}
- The generated TypeScript file is
/**
* Model category
*/
export type category = {
id: number
}
/**
* Model post
*/
export type post = {
id: number
}
Expected behavior
Both category
and type
should contain the fields of each other. Not only they are missing from type, they are also missing from create and others methods.
Prisma information
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model category {
id Int @id @default(autoincrement())
post post[] @relation("categorytopost")
}
model post {
id Int @id @default(autoincrement())
category category[] @relation("categorytopost")
}
Environment & setup
- OS: Debian
- Database: PostgreSQL
- Node.js version: v16.9.1
Prisma Version
prisma : 3.0.2
@prisma/client : 3.0.2
Current platform : debian-openssl-1.1.x
Query Engine (Node-API) : libquery-engine 2452cc6313d52b8b9a96999ac0e974d0aedf88db (at node_modules/@prisma/engines/libquery_engine-debian-openssl-1.1.x.so.node)
Migration Engine : migration-engine-cli 2452cc6313d52b8b9a96999ac0e974d0aedf88db (at node_modules/@prisma/engines/migration-engine-debian-openssl-1.1.x)
Introspection Engine : introspection-core 2452cc6313d52b8b9a96999ac0e974d0aedf88db (at node_modules/@prisma/engines/introspection-engine-debian-openssl-1.1.x)
Format Binary : prisma-fmt 2452cc6313d52b8b9a96999ac0e974d0aedf88db (at node_modules/@prisma/engines/prisma-fmt-debian-openssl-1.1.x)
Default Engines Hash : 2452cc6313d52b8b9a96999ac0e974d0aedf88db
Studio : 0.423.0
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Many-to-many relations - Prisma
In relational databases, m-n-relations are typically modelled via relation tables. m-n-relations can be either explicit or implicit in the Prisma schema.
Read more >Introspection does not generate correct relation #2301 - GitHub
Bug description npx prisma introspect Does not produce relation in documentation. How to reproduce Initialize database CREATE TABLE ...
Read more >Data Modeling with Prisma - JavaScript in Plain English
Implicit m-n relations. In an Implicit m-n relation, relation fields are defined as lists on the two models. Although the relation table exists ......
Read more >Many-to-Many Relationships the Redwood Way™️
Configuring the name of the relation table in implicit many-to-many relations ... Update: Unfortunately, this does not work as described.
Read more >usual notion of rank. A each matrix over R has uch a ...
a rank-preserving homomorphism was to be expected, and gives no information ... above arguments (and also implicit in [3]) which provides a.
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 FreeTop 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
Top GitHub Comments
I think this is expected. The bare types generated for the models only contains scalars. That behaviour is inline with 2.x releases.
I tried the above model and implicit relation is correctly showing and filters and include:
@janpio
PostgreSQL is case-insensitive by default, if the name is unquoted. I have just tried with the following SQL.
It generates
The problem still occurs.