Hey guys, I'm looking for some assistance with Pri...
# orm-help
m
Hey guys, I'm looking for some assistance with Prisma MongoDB. I currently have a
Ticket
model and a
TicketTag
model, pretty much building a support ticketing system, however, I wish to add tags. pretty much how it's documented to implement such a feature is to use a many-to-many implementation as so:
Copy code
model Ticket {
  id                String          @id @default(auto()) @map("_id") @db.ObjectId
  title             String
  editedAt          DateTime?
  createdAt         DateTime
  ticketTags        TicketTag[]        @relation(fields: [ticketTagIds], references: [id])
  ticketTagIds      String[]         @db.ObjectId
  user              User             @relation(fields: [userId], references: [id])
  userId            String           @db.ObjectId
}

model TicketTag {
  id                String          @id @default(auto()) @map("_id") @db.ObjectId
  title             String
  description       String?
  attributes        Json
  editedAt          DateTime?
  createdAt         DateTime
  tickets           Ticket[]        @relation(fields: [ticketIds], references: [id])
  ticketIds         String[]         @db.ObjectId
}
But it seems incredibly unoptimized to stack for example 50,000 tickets into the
ticketIds
field on the
TicketTag
, as I'm aware MongoDB has a 16MB document limit. My question is, is how can I get only
Ticket
to store the
ticketTagIds
without also doing the same on
TicketTag
model
1
Referencing the documentation, it's recommended I do exactly this, what about if one category has a million posts?
Copy code
model Post {
  id          String     @id @default(auto()) @map("_id") @db.ObjectId
  categoryIDs String[]   @db.ObjectId
  categories  Category[] @relation(fields: [categoryIDs], references: [id])
}

model Category {
  id      String   @id @default(auto()) @map("_id") @db.ObjectId
  postIDs String[] @db.ObjectId
  posts   Post[]   @relation(fields: [postIDs], references: [id])
}
Referencing this article: https://github.com/prisma/prisma/issues/12552 Looks to be I'm to wait for an update and accept the fact I just have to use a hacky way to achieve this.
n
Hey Matt! 👋 Your use case is valid, but we do not allow one-way relations yet. If you add a relation in one direction, we automatically also add the other direction. We have added this to our improvements board, so we will indeed work to improve this experience.