Skip to content
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

MongoDB: Quick fix for missing @map("_id") annotation #762

Closed
Tracked by #8788
janpio opened this issue Apr 12, 2021 · 3 comments · Fixed by prisma/prisma-engines#3985
Closed
Tracked by #8788

MongoDB: Quick fix for missing @map("_id") annotation #762

janpio opened this issue Apr 12, 2021 · 3 comments · Fixed by prisma/prisma-engines#3985
Labels
domain/schema Issue in the "Schema" domain: Prisma Schema, Introspection, Migrations etc. kind/feature A request for a new feature. topic: mongodb topic: quick fix
Milestone

Comments

@janpio
Copy link
Contributor

janpio commented Apr 12, 2021

image

@janpio janpio added the kind/feature A request for a new feature. label Apr 12, 2021
@tomhoule tomhoule added the domain/schema Issue in the "Schema" domain: Prisma Schema, Introspection, Migrations etc. label Sep 23, 2021
@tomhoule
Copy link
Contributor

@matthewmueller do you think this should be prioritized for mongo GA?

@Jolg42 Jolg42 added the process/candidate Candidate for next Milestone. label Nov 16, 2021
@matthewmueller
Copy link
Contributor

matthewmueller commented Nov 16, 2021

I could see this being a nice-to-have for sure. It seems that people like that our formatter auto-writes back-relations. I could see us extending that concept here as well. Some ideas:

Scenario 1: You're using the mongodb provider, you add @id to a String field, hit save.

Before (cursor is |):

model User {
  id String @id|
  firstName String
}

I could see this auto-writing the following:

model User {
  id String @id @default(dbgenerated()) @map("_id") @db.ObjectId|
  firstName String
}

Of course, if you edit any of this, it doesn't try to re-correct. It only adds under the conditions above, it never changes, deletes, or duplicates. I assume there's some element of playing around with it until it feels right.

Scenario 2: You're using the mongodb provider, you add @id to a Int field, hit save.

Before (cursor is |):

model User {
  id Int @id|
  firstName String
}

I could see this auto-writing the following:

model User {
  id Int @id @map("_id")|
  firstName String
}

Again, we'd need to be conservative about when we auto-write.

Added as a nice-to-have to the epic.

@janpio
Copy link
Contributor Author

janpio commented Nov 16, 2021

Note: Hitting save does not do anything by default, you need to manually configure VSCode to run "format on save".
A quick fix is a feature that is native to VSCode that does not need that configuration instead.

@tomhoule tomhoule removed the process/candidate Candidate for next Milestone. label Nov 17, 2021
@Jolg42 Jolg42 added the process/candidate Candidate for next Milestone. label Dec 17, 2021
@janpio janpio removed the process/candidate Candidate for next Milestone. label Jan 15, 2022
@janpio janpio added the process/candidate Candidate for next Milestone. label Jan 29, 2022
@floelhoeffel floelhoeffel removed the process/candidate Candidate for next Milestone. label Feb 2, 2022
@matthewmueller matthewmueller changed the title Quick fix for missing @map("_id") annotation with mongo MongoDB: Quick fix for missing @map("_id") annotation Feb 16, 2022
@Druue Druue added this to the 4.15.0 milestone May 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain/schema Issue in the "Schema" domain: Prisma Schema, Introspection, Migrations etc. kind/feature A request for a new feature. topic: mongodb topic: quick fix
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants