fdarian / prisma-generator-drizzle

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

Foreign key is not correctly generated for implicit M:N relations #55

Closed jansedlon closed 4 months ago

jansedlon commented 4 months ago

Hey, sorry for another issue :) My colleague found your package so i'm trying to integrate it.

We have a an implicit M:N relation

model Country {
  id String @id @default(cuid())
  // ...
  currencies Currency[]
}

model Currency {
  code String @id @unique
  countries Country[]
  // ...
}

The main thing here is that Currency's id is code.

This is the relations that this package generates. See the comment

export const countriesToCurrenciesRelations = relations(
  countriesToCurrencies,
  (helpers) => ({
    country: helpers.one(countries, {
      fields: [countriesToCurrencies.A],
      references: [countries.id],
    }),
    currency: helpers.one(currencies, {
      fields: [countriesToCurrencies.B],
      references: [currencies.id], // Property 'id' does not exist on type. It should be `code`
    }),
  }),
);
fdarian commented 4 months ago

That's new, I think this should be an easy fix, brb

fdarian commented 4 months ago

@jansedlon could you please try again with prisma-generator-drizzle@0.7.3-adc7351?

jansedlon commented 4 months ago

@farreldarian tsc doesn't complain anymore, thanks a lot!