Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

manyMany join tables are not generated #46

Open
maxmousse opened this issue Apr 25, 2023 · 7 comments · Fixed by #49
Open

manyMany join tables are not generated #46

maxmousse opened this issue Apr 25, 2023 · 7 comments · Fixed by #49

Comments

@maxmousse
Copy link
Contributor

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 [email protected].

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

@pauldeste
Copy link

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

@maxmousse
Copy link
Contributor Author

@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.

@maxmousse
Copy link
Contributor Author

maxmousse commented Apr 29, 2023

So I made some tests by runnig the generator with [email protected], 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.

@marcjulian marcjulian linked a pull request May 2, 2023 that will close this issue
@marcjulian
Copy link
Member

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

npm install -D [email protected]

Let me know if this is fixed on your side.

@maxmousse
Copy link
Contributor Author

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

@omarkhatibco
Copy link

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

npm install -D [email protected]

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

@timreibe
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants