kimjbstar / prisma-class-generator

Class generator from Prisma schema.
176 stars 50 forks source link

fixed bug for 1:1 self-relations in separate relation classes #58

Closed jannis6023 closed 9 months ago

jannis6023 commented 9 months ago

checking for wether using separateRelationFields => then add import in relation file, if not then don't generate relation import.

jannis6023 commented 9 months ago

Here's an example prisma scheme with the bug-producing relation - is fixed in this pull request!

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

generator clent {
  provider      = "prisma-client-js"
  binaryTargets = ["native", "rhel-openssl-1.0.x", "darwin"]
}

generator prismaClassGenerator {
  provider               = "node -r ts-node/register/transpile-only src/index.ts"
  output                 = "../src/_gen/prisma-class"
  dryRun                 = "false"
  separateRelationFields = "true"
}

model Person {
  id      Int       @id @default(autoincrement())
  Company Company[]
}

model Company {
  id             Int      @id
  childCompany   Company? @relation("parent_child", fields: [childCompanyId], references: [id])
  childCompanyId Int?     @unique
  parentComany   Company? @relation("parent_child")
  owner          Person   @relation(fields: [personId], references: [id])
  personId       Int
}
jannis6023 commented 9 months ago

@kimjbstar Thanks for your fast merge! Could you also run a npm publish for a new version number, so we can import it in our projects? Thanks!

KoKawanabe commented 6 months ago

@kimjbstar I'm also eagerly awaiting the npm publish. Can't wait to use the new updates in our projects!

jannis6023 commented 6 months ago

Hi, we are waiting as well. Therefor, we published the fork: @jannis6023/prisma-class-generatorBest Regards,JannisAm 19.04.2024 um 03:10 schrieb Ko Kawanabe @.***>: @kimjbstar I'm also eagerly awaiting the npm publish. Can't wait to use the new updates in our projects!

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: @.***>