notiz-dev/prisma-dbml-generator

manyMany join tables are not generated

maxmousse opened this issue ยท 7 comments

I there,

First thank you for maintaining this prisma generator, it's very useful =)

Problem

I'm reporting this issue cause I am not able to have the manyMany join tables generated

How to reproduce

I am using prisma@4.12.0.

Here is my prisma schema:

// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

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

generator client {
  provider        = "prisma-client-js"
  output          = "./node_modules/.prisma/client"
  previewFeatures = []
}

generator dbml {
  provider   = "prisma-dbml-generator"
  output     = "."
  outputName = "schema.dbml"
  manyToMany = true
  includeRelationFields = false
  projectDatabaseType = "postgreSQL"
}


model MarketZone {
  id          String    @id @default(uuid())
  name        String
  description String

  // Relations
  marketActors MarketActor[]
}

model MarketActor {
  id          String    @id @default(uuid())
  name        String
  marketActorTypeId String

  marketZones  MarketZone[]
}

and here is the generator output:

//// ------------------------------------------------------
//// THIS FILE WAS AUTOMATICALLY GENERATED (DO NOT MODIFY)
//// ------------------------------------------------------

Table MarketZone {
  id String [pk]
  name String [not null]
  description String [not null]
}

Table MarketActor {
  id String [pk]
  name String [not null]
  marketActorTypeId String [not null]
}

If that's a bug, I'd be happy to help fix it =)

Hi @maxmousse, I have the same problem, did you find a fix or a workaround?

@pauldeste I did not have time to look for a solution yet. Maybe this week-end. If the feature was working before, my first guess is that something changed in @prisma/internals, that breaks the feature.

So I made some tests by runnig the generator with prisma@4.12.0, and it appears that the representation of fields of type manyMany has changed in the DMMF from:

        {
          "name": "categories",
          "kind": "object",
          "isList": true,
          "isRequired": true,
          "isUnique": false,
          "isId": false,
          "isReadOnly": false,
          "hasDefaultValue": false,
          "type": "Category",
          "relationName": "CategoryToPost",
          "relationFromFields": [],
          "relationToFields": ["id"],
          "isGenerated": false,
          "isUpdatedAt": false
        }

to:

        {
          "name": "categories",
          "kind": "object",
          "isList": true,
          "isRequired": true,
          "isUnique": false,
          "isId": false,
          "isReadOnly": false,
          "hasDefaultValue": false,
          "type": "Category",
          "relationName": "CategoryToPost",
          "relationFromFields": [],
          "relationToFields": [],
          "isGenerated": false,
          "isUpdatedAt": false
        }

The key relationToFields was previously containig the name of the field refered in the manyMany relation, allowing to discriminate it from the many side of oneMany relations. But that's not the case anymore (I don't know in wich version this change was introduced).

I think the function in charge of getting the manyMany fields must be updated, as well as the logic to generate the join table in the dbml.

@marcjulian, if you agree with this, I can open a pull request =). However, I don't know how you deal with version compatibility between this generator and prisma.

Thanks for @maxmousse PR this should be fixed and you can test it in the latest dev release

npm install -D prisma-dbml-generator@0.11.0-dev.0

Let me know if this is fixed on your side.

Hello @marcjulian, thanks for the review and merging the PR. I tried the new version of the package, and the manyMany join tables are back in the generated dbml, so it's working for me =)

Thanks for @maxmousse PR this should be fixed and you can test it in the latest dev release

npm install -D prisma-dbml-generator@0.11.0-dev.0

Let me know if this is fixed on your side.

I just tried it with Prisma v5.1.1 and it's working again, thank you for the fix

I guess this issue can be closed since it's fixed?