Hello everyone, I have a question please. With rel...
# orm-help
s
Hello everyone, I have a question please. With relationships (eg users / posts) is it possible to get a relationship with a specific role? I would like to get user in model post with role specific (client for exemple) I have this:
Copy code
model User {
  id          String   @id @default(uuid())
  username    String
  roleId      String?
  role        Role?    @relation(fields: [roleId], references: [id])
  contact     Contact?
  acceptCGU   Boolean  @default(false)
  opinons Opinion[]
}

model Role {
  id              String           @id @default(uuid())
  name            String
  description     String
  rolePermissions RolePermission[]
  users           User[]
}

model Opinion {
  id        String   @id @default(uuid())
  opinionCount     Int?
  descriptionOpinion   String?
  user     User      @relation(fields: [authorId], references: [id])
  authorId String
  createdAt DateTime @default(now())
}
r
@Simoh 2k 👋 If you’re looking for a User in the Opinion model, you will always get a single user regardless of the role as it’s a 1-many relation from Opinion to User. You can’t filter because there’s only 1 item.
You would need to directly search in users if you want a user with a specific role.
s
Ok thank's Ryan
👍 1