Hi all, is something like this possible and recomm...
# orm-help
a
Hi all, is something like this possible and recommended when it makes sense?
Copy code
model Group {
  id         String        @id @default(cuid())
  members    User[] @relation(fields: [memberIds], references: [id])
  memberIds   String[]
}
c
No, don't do that, you can't do SQL joins or ensure referential integrity with foreign keys. See Modeling and querying many-to-many relations | Prisma Docs.
1
r
@Ariel Flesler 👋 I second with Chris but I would love to know your use case for this.
a
Hi @Ryan, here are some potential upsides of (roughly) something like this: • Less tables. It's easy to have the DB grow into hell with all the many-to-many relationships • Having the ids available in the entity. A lot of the time you just need the ids . Otherwise one must load them from the intermediate table • Having a UNIQUE restriction on that (assuming ids are consistently sorted). I don't want to have many channels for the same combination of users
r
For the above points, having separate tables with proper indexing will be better as Prisma can easily fetch the required relations and easily connect related records. As for the third point, you can also do that with many-to-many relations by keeping a join table of id’s. Prisma also doesn’t allow having an array of id’s as it will automatically reference the opposite relation in the other table.