-
-
Notifications
You must be signed in to change notification settings - Fork 36
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
Support implicit many-to-many relations #12
Comments
Here are the conventions for the table (name, columns, etc): https://www.prisma.io/docs/concepts/components/prisma-schema/relations/many-to-many-relations#conventions-for-relation-tables-in-implicit-m-n-relations |
Here's a link to the code and the tests for the code. |
Here's an example: Schema:datasource db {
provider = "sqlite"
url = "file:./dev.db"
}
generator kysely {
provider = "node ./dist/bin.js"
camelCase = true
}
model User {
id Int @id @default(autoincrement())
publicId String
email String @unique
password String?
firstName String
lastName String
profilePictureUrl String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
groups Group[]
}
model Group {
id Int @id @default(autoincrement())
name String
users User[]
} Output:import type { ColumnType } from "kysely";
export type Generated<T> = T extends ColumnType<infer S, infer I, infer U>
? ColumnType<S, I | undefined, U>
: ColumnType<T, T | undefined, T>;
export type Timestamp = ColumnType<Date, Date | string, Date | string>;
export type Group = {
id: Generated<number>;
name: string;
};
export type GroupToUser = {
A: number;
B: number;
};
export type User = {
id: Generated<number>;
publicId: string;
email: string;
password: string | null;
firstName: string;
lastName: string;
profilePictureUrl: string | null;
createdAt: Generated<Timestamp>;
updatedAt: Timestamp;
};
export type DB = {
Group: Group;
GroupToUser: GroupToUser;
User: User;
}; |
Oh wait the name of the table is missing an underscore! My bad. I'll fix this in a PR tomorrow. |
I forgot to mention - I am using 1.0.9 version. The (simplified) schema:datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}
generator kysely {
provider = "prisma-kysely"
}
model MenuItem {
id String @id @default(cuid())
category Category[]
}
model Category {
id String @id @default(cuid())
menuItems MenuItem[]
} Output:import type { ColumnType } from "kysely";
export type Generated<T> = T extends ColumnType<infer S, infer I, infer U>
? ColumnType<S, I | undefined, U>
: ColumnType<T, T | undefined, T>;
export type Timestamp = ColumnType<Date, Date | string, Date | string>;
export type Category = {
id: string;
};
export type MenuItem = {
id: string;
};
export type DB = {
Category: Category;
MenuItem: MenuItem;
}; No |
Hm, that's interesting. When I tried to generate from the cloned repo it generated a relation table (w/o leading underscore, but still). |
I did some console logging and it seems |
Oh, strange! I need to take a good look at this part of the codebase. It was hastily ripped from another library. I might not have adapted it properly. If you find the issue in the meantime though feel free to submit a PR (and add a test case so this doesn't happen again) 😄 |
Seems to be some change from version |
Huh, must be some breaking change in Prisma. I'll look into this as soon as I get a chance. |
Turns out this was caused by a breaking change in Prisma's DMMF where the "relationToFields" entry on fields is now empty (nice catch @Aulos). Found a good reference in this issue: notiz-dev/prisma-dbml-generator#46. I've created a fix for this in pr #28. It would be super helpful if you guys could try it out using snapshot @janpio is there some place where breaking changes to the DMMF format are announced, or should we treat this as an internal API?
|
Unfortunately, I migrated to explicit many-to-many 😢 |
Oh well, sorry for the delay. I think for projects that are only using Kysely explicit many to many relationships are probably better in most cases anyways. This is mainly meant to support people that are adding Kysely to a project that already heavily uses the Prisma JS client. |
hey there @valtyr! thanks for your work on this. just updated to
if I keep the
then if I remove it, I get this (with TagToUpload)
any thoughts? |
@sgrund14 Thank you for the detailed report! The release might have been a bit premature hmmm. I'll add more test cases later today and see if I can get this sorted. |
thanks much 😄 |
I'm missing one-to-many types as well tried on both prisma 4.x and 5.x |
Also missing many-to-many types on |
Missing many to many types on prisma 5.1.1 and prisma-kysely 1.6.0 |
Hey there. For everyone that's been following this issue, I'm about to release version 1.7.0 that should fix the issue! Thanks for the patience and huuuuge thanks to @dextertanyj for submitting a pull request with the fix! |
It seems Prisma creates a relation table to connect two tables, but
prisma-kisely
does not create a type for it. I am not sure how the relation table is generated, but it seems to have_{Tab1}On{Tab2}
name andA
andB
(sic!) columns.The text was updated successfully, but these errors were encountered: