valtyr / prisma-kysely

🪄 Generate Kysely types directly from your Prisma schema!
https://www.npmjs.com/package/prisma-kysely
MIT License
951 stars 36 forks source link

[BUG] Implicit join table key type could be in the wrong order #86

Closed Bayezid1989 closed 6 months ago

Bayezid1989 commented 11 months ago

Hi, I probably founded a minor bug for implicit join table type. Version: 1.7.1

Here is a sample schema that has 2 models that joined m-n way.

model Shop {
    id         Int        @id @default(autoincrement())
    name       String
    categories Category[]
}

model Category {
    name  String @id
    shops Shop[]
}

In this case, the following is correctly created, which corresponds to the actual created table.

export type CategoryToShop = {
  A: string;
  B: number;
};

[Bug case] On the other hand, if I name the join field from "shops" to "businesses",

model Shop {
    id         Int        @id @default(autoincrement())
    name       String
    categories Category[]
}

model Category {
    name       String @id
    businesses Shop[]
}

Types of A and B become opposite, which doesn't match with the actual table.

export type CategoryToShop = {
  A: number;
  B: string;
};