Hi, I've seen amazing improvements with the latest releases on the Prisma database schema creation, around the fact of being less opinioned. That made me really happy and I'm absolutely appreciating the effort.
Although I have a simple request for you to consider since now my Database looks much nicer than before with lesser tables and custom names.
Would you consider renaming the columns for a Table driven relation from A and B to something like {tableName}ID or even better have them customisable?
It would make things even nicer and more fluent when writing ad hoc SQL queries.
Is it also currently possible to customise the Table names for those pivot tables?
Thanks again for building Prisma. Definitely, something I'm investing so much in.
Hi @fenos
You can actually do this with the new datamodel using the @db directive. Also, you can configure the link tables using the @relationTable directive. Here is an example:
type User @db(name: "user") {
id: ID! @id
createdAt: DateTime! @createdAt
email: String! @unique
name: String
role: Role @default(value: USER)
posts: [Post!]!
profile: Profile @relation(link: INLINE)
}
type Profile @db(name: "profile") {
id: ID! @id
user: User!
bio: String!
}
type Post @db(name: "post") {
id: ID! @id
createdAt: DateTime! @createdAt
updatedAt: DateTime! @updatedAt
author: User!
published: Boolean! @default(value: false)
categories: [Category!]! @relation(link: TABLE, name: "PostToCategory")
}
type Category @db(name: "category") {
id: ID! @id
name: String!
posts: [Post!]! @relation(name: "PostToCategory")
}
type PostToCategory @db(name: "post_to_category") @relationTable {
post: Post
category: Category
}
enum Role {
USER
ADMIN
}
You can also use @db in a field as well.
I was today years old to know this. Isn't this documented in prisma 1 docs @pantharshit00 ?
And I've such relations table in my database and it's hard to identify which table does column A and B belongs to.
Yeah, documentation work for Prisma 1 has stopped. You can find it in docs for Prisma 2. It gives you even more control now: https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-schema/relations#relation-tables