Skip to content
This repository has been archived by the owner on Jan 14, 2021. It is now read-only.

Using a relation as @id or in @@unique doesn't work #534

Closed
julien1619 opened this issue Feb 27, 2020 · 3 comments
Closed

Using a relation as @id or in @@unique doesn't work #534

julien1619 opened this issue Feb 27, 2020 · 3 comments
Labels
bug/2-confirmed We have confirmed that this is a bug. kind/bug A reported bug. topic: AUMFIDARR
Milestone

Comments

@julien1619
Copy link

When I try to use @@unique it doesn't error and seems to be implemented in the engine but the generated code only show scalar fields.

When I use a relation as an @id or inside a @@unique as specified in these tests prisma/prisma-engines@4108df5 the generated code does not contain the relation fields in WhereUniqueInput, only scalar fields are present.

Is it a bug or is it only supported by the engine but not in the generated code?

Example with @@unique:

schema.prisma

model Company {
  id   String @default(uuid()) @id
  name String
}

model Subside {
  id        String  @default(uuid()) @id
  company   Company @relation(references: [id])
  reference String

  @@unique([company, reference])
}

Generated code

export type ReferenceCompoundUniqueInput = {
  reference: string
}

export type SubsideWhereUniqueInput = {
  id?: string | null
  company_reference?: ReferenceCompoundUniqueInput | null
}

Example with @id:

schema.prisma

model Company {
  id   String @default(uuid()) @id
  name String
}

model CompanyData {
  id        Company  @relation(references: [id]) @id
  someData String
}

Generated code doesn't contain any findOne, update, ... Only operations on many objects are generated.

Related to #306

@mavilein
Copy link
Member

This will be fixed by this internal work package: prisma/prisma-engines#543

@pantharshit00 pantharshit00 added bug/2-confirmed We have confirmed that this is a bug. kind/bug A reported bug. labels Feb 28, 2020
@janpio
Copy link
Member

janpio commented Mar 19, 2020

Example with @@unique:

schema.prisma

model Company {
  id   String @default(uuid()) @id
  name String
}

model Subside {
  id        String  @default(uuid()) @id
  company   Company @relation(references: [id])
  reference String

  @@unique([company, reference])
}

Generated code

export type ReferenceCompoundUniqueInput = {
  reference: string
}

export type SubsideWhereUniqueInput = {
  id?: string | null
  company_reference?: ReferenceCompoundUniqueInput | null
}

This looks much better now:

export type CompanyReferenceCompoundUniqueInput = {
  company: string
  reference: string
}

export type SubsideWhereUniqueInput = {
  id?: string | null
  company_reference?: CompanyReferenceCompoundUniqueInput | null
}

Example with @id:

schema.prisma

model Company {
  id   String @default(uuid()) @id
  name String
}

model CompanyData {
  id        Company  @relation(references: [id]) @id
  someData String
}

Generated code doesn't contain any findOne, update, ... Only operations on many objects are generated.

Similar here:
image

(Tested with prisma2@2.0.0-alpha.934)

Can you please confirm that I did not misunderstand and this also works for you @julien1619?

@janpio janpio closed this as completed Mar 19, 2020
@julien1619
Copy link
Author

It's perfect, thank you!

@janpio janpio added this to the Preview 25 milestone Mar 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug/2-confirmed We have confirmed that this is a bug. kind/bug A reported bug. topic: AUMFIDARR
Projects
None yet
Development

No branches or pull requests

4 participants