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.

Implicit m-n-relations no longer works in v3

See original GitHub issue

Bug description

TypeScript file generated by the client does not contain m-n-relations.

How to reproduce

  1. 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);
  1. 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")
}
  1. 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:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
pantharshit00commented, Sep 21, 2021

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: image

1reaction
joshuaavaloncommented, Sep 19, 2021

@janpio

PostgreSQL is case-insensitive by default, if the name is unquoted. I have just tried with the following SQL.

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);

It generates

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

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

model Category {
  id   Int    @id @default(autoincrement())
  Post Post[]
}

model Post {
  id       Int        @id @default(autoincrement())
  Category Category[]
}

/**
 * Model Category
 */

export type Category = {
  id: number
}

/**
 * Model Post
 */

export type Post = {
  id: number
}

The problem still occurs.

Read more comments on GitHub >

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

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