Hey guys quick question about schema design I hav...
# orm-help
p
Hey guys quick question about schema design I have 3 tables, hashtag, image and ImageHashtags (+ 1 profile table) looking like this
Copy code
model Hashtag {
  id            String?         @unique
  name          String          @id
  thumbnail     String?
  post_count    Int?
  images        Image[]
  imageHashtags ImageHashtags[]

  @@map("hashtag")
}

model Image {
  id              String           @id
  thumbnail       String
  shortcode       String           @unique
  like_count      Int
  comment_count   Int
  caption         String?          @db.Text 
  hashtag         Hashtag?         @relation(fields: [hashtagName], references: [name])
  hashtagName     String?
  imageHashtags   ImageHashtags[]
  
  @@index([hashtagName])
  @@map("image")
} 

// Explicit m-n relation good fit for this use case? 
model ImageHashtags {
  imageId String
  image   Image   @relation(fields: [imageId], references: [id])
  name    String
  hashtag Hashtag @relation(fields: [name], references: [name])
  count   Int  

  @@id([imageId, name])
}
i'm using the ImageHashtags table to keep a count of how many hashtags were used in an image caption to later aggregate on the hashtag name to find out how often a profile uses a specific hashtag this is working fine but it pollutes my database a lot... right now I have about 10k image rows and 100k rows in the ImageHashtags. is there a way to do this more effectively to reduce row writes?
this is how ImageHashtags looks like in the end