hey! is there a way of `@map`-ing the relationship...
# prisma-client
k
hey! is there a way of
@map
-ing the relationship tables - for instance i want my
_OrgToUser
join table to be
_org_to_user
? i can’t seem to find it in the docs
Got a follow-up question on this! Given the join table
_OrgToUser
I know I can rename that now. Is it also possible to rename the columns of that table — they’re right now called
A
and
B
which is very cryptic plus capitalized which isn’t normal SQL-convention. Trying to make sure our data team doesn’t hate me.
n
Unfortunately the column names are hard requirements for Prisma to pick up the relation table…
But I could see this become configurable in the future, do you maybe mind opening a feature request for this (ideally also including the use case for it)?
k
To circumvent this we started with a convention to explicitly always define the relationship table. But it has more pros: • Can add
createdAt
updatedAt
on relationships as well • Can easily store more meta data on the relationship • All tables that exists are now explicitly declared in
*.prisma
• Easier control over relationship table name • Control over join table columns • No hidden Prisma-magic when connecting/disconnecting Cons: • Slightly more typing in Prisma • Slightly more typing when “connecting”/“disconnecting”
👍 1
Example:
Copy code
model OrgUser {
  orgId     String @map("org_id")
  userId    String @map("user_id")
  createdAt DateTime @default(now()) @map("created_at")
  updatedAt DateTime @default(now()) @map("updated_at")

  User User @relation(fields: [userId], references: [id])
  Org  Org  @relation(fields: [orgId], references: [id])

  @@id([orgId, userId])
  @@map("_orgs_to_users")
}
n
Interesting! I guess it makes sense to sacrifice the convenience in the Prisma Client API for the benefits you get here 👍