prisma-case-format
prisma-case-format copied to clipboard
MongoDB ID field issue
Hi,
I found this same issue in the library https://github.com/loop-payments/prisma-lint
and that's why I tried this one for case linting of tables and field for a model of MongoDB in Prisma.
The issue is the following:
In MongoDB the id field is not Snake or Pascal case. The id
is named by convention _id
.
Example in Prisma Documentation:
https://www.prisma.io/docs/getting-started/setup-prisma/start-from-scratch/mongodb/creating-the-prisma-schema-typescript-mongodb
model Post {
id String @id @default(auto()) @map("_id") @db.ObjectId
slug String @unique
title String
body String
author User @relation(fields: [authorId], references: [id])
authorId String @db.ObjectId
comments Comment[]
}
So the issue is that the prisma-case-format
is removing the @map("_id")
from the Prisma schema, when the idea is to keep that special mapping from id
to _id
.
This is a general rule and not something that should be added as an override table by table.
Thanks!
So essentially, if provider = "mongodb"
then id
shall map to _id
So essentially, if
provider = "mongodb"
thenid
shall map to_id
Yes, that's correct.
Give the option to omit some specific field without link that field to a table should be the way to go. Something like:
default: ...
override:
mYTaBlE: 'disable' # skip convention management for this table
...
YourTable:
default: '...'
field:
unmanaged_property: 'disable' # skip convention management for this field
override-field:
id: 'disable'
Or if that is too hard perhaps another solution is to add the option of adding a comment to disable from the process the next line after a special comment, like the linting tools have. Something like:
model Post {
// prisma-case-format-disable-next-line
id String @id @default(auto()) @map("_id") @db.ObjectId
slug String @unique
title String
body String
author User @relation(fields: [authorId], references: [id])
authorId String @db.ObjectId
comments Comment[]
}
I mean this sounds like it's a fundamentalism of using mongodb
, so I'd think we shouldn't make this configurable, it should be embedded. Probably the way I'd build it under the hood is to implement common field overrides, and then when it's detected that "mongodb" is the provider
, create an ad hoc common field override for @id
.
Yes, I totally agree with you. That's an even better solution!
@daeteck have you solved it somehow?