Skip to content

Instantly share code, notes, and snippets.

@scriptcoded
Created December 12, 2019 13:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scriptcoded/aff820c37339b3d9e7b9ec884cda48b3 to your computer and use it in GitHub Desktop.
Save scriptcoded/aff820c37339b3d9e7b9ec884cda48b3 to your computer and use it in GitHub Desktop.
model Company {
id String @default(cuid()) @id
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
workspaceId Int @unique
name String
users User[]
}
model User {
id String @default(cuid()) @id
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
workspaceId Int @unique
givenName String?
familyName String?
email String
companies Company[]
}
model CompanyUsers {
id String @id
company Company
user User
roles String[]
}
@matthewmueller
Copy link

I think this should work:

model Company {
  id          String   @default(cuid()) @id
  createdAt   DateTime @default(now())
  updatedAt   DateTime @updatedAt
  workspaceId Int      @unique
  name        String
  companyUsers       CompanyUser[]
}

model User {
  id          String   @default(cuid()) @id
  createdAt   DateTime @default(now())
  updatedAt   DateTime @updatedAt
  workspaceId Int      @unique
  givenName   String?
  familyName  String?
  email       String
  companyUsers       CompanyUser[]
}

model CompanyUsers {
  id      String   @id
  company Company
  user    User
  roles   String[]
}

@ifndefdeadmau5
Copy link

ifndefdeadmau5 commented Dec 13, 2019

Hi @matthewmueller, what makes the difference from your another workarounds about explicit many-to-many described in prisma/prisma#816 (comment) ?

In above schema, both model has a list of relation model while in the gist they directly have list of each others

@scriptcoded
Copy link
Author

@ifndefdeadmau5 It was a mistake and the wrong syntax. See the link below. The syntax here is the correct one :)

https://prisma.slack.com/archives/CKQTGR6T0/p1576156448333900?thread_ts=1576156170.333700&cid=CKQTGR6T0

@matthewmueller
Copy link

yep thanks @scriptcoded. sorry for the confusion!

@ifndefdeadmau5
Copy link

@scriptcoded Thanks for the correction :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment