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

VSCode: Better way to create relations #782

Open
janpio opened this issue May 22, 2021 · 1 comment
Open

VSCode: Better way to create relations #782

janpio opened this issue May 22, 2021 · 1 comment
Labels
domain/schema Issue in the "Schema" domain: Prisma Schema, Introspection, Migrations etc. kind/feature A request for a new feature. topic: vscode

Comments

@janpio
Copy link
Contributor

janpio commented May 22, 2021

Problem

The relations syntax of Prisma is quite involved: https://www.prisma.io/docs/concepts/components/prisma-schema/relations

To go from

model User {
  id      Int      @id @default(autoincrement())
}

model Post {
  id         Int         @id @default(autoincrement())
  authorId   Int
}

to

model User {
  id      Int      @id @default(autoincrement())
  posts   Post[]
}

model Post {
  id         Int         @id @default(autoincrement())
  authorId   Int
  author     User        @relation(fields: [authorId], references: [id])
}

or alternatively to create something like

model User {
  id             Int     @default(autoincrement()) @id
  name           String?
  successorId Int?
  successor   User?   @relation("BlogOwnerHistory", fields: [successorId], references: [id])
  predecessor User?   @relation("BlogOwnerHistory")
}

you need to

  1. know and type a new field with a model type
  2. know and type @relation
  3. know any type fields and know that its value has to point to the relation scalar field (= FK field)
  4. know and type references and know that its value has to reference the other, referenced field
  5. optionally also know when the @relation needs to be named for disambiguation

Suggested Solution

It would be amazing if the Prisma VSCode extension could help me create the relation between to models.

  • I could select to models, then define which one should link to the other, select the relation scalar and be lead through the further decisions - and the code is generated.
  • Or I could select the relation scalar, and then be lead through the decisions to set up the relation - and the code is generated.

It is unclear to me what that would look like in VSCode, what UI is appropriate in that context.

@janpio janpio added kind/feature A request for a new feature. topic: vscode labels May 22, 2021
@Jolg42 Jolg42 added the domain/schema Issue in the "Schema" domain: Prisma Schema, Introspection, Migrations etc. label Nov 16, 2021
@Druue
Copy link
Contributor

Druue commented Jul 18, 2024

It is unclear to me what that would look like in VSCode, what UI is appropriate in that context.

This to me seems like code-actions or refactorings would be appropriate.

Currently there is very limited interactivity available. There is the option to move the user cursor around to effectively prompt the user to type in what they want but it's not quite as advanced as what you describe.

If I understand correctly, it seems the following issue is more in line: LSP#1579, in which case, this is pending upstream changes

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: vscode
Projects
None yet
Development

No branches or pull requests

3 participants