fdarian / prisma-generator-drizzle

A Prisma generator for generating Drizzle schema with ease
129 stars 11 forks source link

Separate relational definitions into a separate module #13

Closed fdarian closed 8 months ago

fdarian commented 9 months ago

Resolves #11

Scalahansolo commented 9 months ago

While messing around with the lib last night I noticed a bug that Im not sure would be solved by this.

When a model references itself as a relation like....

model Post {
    subPosts    Post[]
}

It seems like the generated file tries to import itself for the relation.

fdarian commented 9 months ago

While messing around with the lib last night I noticed a bug that Im not sure would be solved by this.

When a model references itself as a relation like....

model Post {
    subPosts    Post[]
}

It seems like the generated file tries to import itself for the relation.

Sorry, I've just had the chance to check, I just added the test for self-reference and it works just fine, also I think this PR isn't related to the problem. Could you please provide a reproductive case where it fails?

Scalahansolo commented 9 months ago

In the cases of my schema where I notice the issue is definitely in the few places where a model has a self referencing relation. So if those relations are now broken out into their own files, I would expect that to be working properly.

fdarian commented 9 months ago

In the cases of my schema where I notice the issue is definitely in the few places where a model has a self referencing relation. So if those relations are now broken out into their own files, I would expect that to be working properly.

So this is the test schema that I added

https://github.com/farreldarian/prisma-generator-drizzle/blob/6c92c8923187dfd01c707ebb9a2d5e601dcf60ac/packages/usage/prisma/schema.prisma#L59

model SelfReference {
  id String @id
  referringManyId String?
  referringMany   SelfReference?  @relation("SelfReference_referringMany", fields: [referringManyId], references: [id])
  referredMany    SelfReference[] @relation("SelfReference_referringMany")
  referringUniqueId String?        @unique
  referringUnique   SelfReference? @relation("SelfReference_referringUnique", fields: [referringUniqueId], references: [id])
  referredUnique    SelfReference? @relation("SelfReference_referringUnique")
}

As well as the test: https://github.com/farreldarian/prisma-generator-drizzle/blob/pgd-11-circular-dependency-on-generated-schema/packages/usage/tests/shared/testSelfReferring.ts

All is working as expected, do you encounter a specific error that I could look at? you could try by installing the 0.5.4-9955142 version

Scalahansolo commented 8 months ago

Hey, sorry for the delay I'll take a look at if the new version solves what I was seeing.

Scalahansolo commented 8 months ago

@farreldarian I just ran a quick test with the separated relations with the 0.5.4 version you gave me and the issue I was seeing is now gone

fdarian commented 8 months ago

Quick test with the separated relations with the 0.5.4 version you gave me and the issue I was seeing is now gone

Awesome! I'm just gonna merge this now, if anything comes up please feel free to raise a new issue