Albert Luft
05/31/2021, 2:26 PMmult-field id :
I have two tables, generic_articles and translations. Multiple articles can have the same name, so generic_article_name is not @unique, and one generic_article_name returns all translations for that name, making it a many to many relationship.
model generic_articles {
generic_article_id Int @id
generic_article_name Int
generic_article_names generic_article_names[]
}
model translations {
term_id Int
language_id Int
term String @db.VarChar(60)
generic_articles generic_article_names[]
@@id([term_id, language_id])
}
model generic_article_names {
generic_article generic_articles @relation(fields: [generic_article_id], references: [generic_article_name])
generic_article_id Int
translation translations @relation(fields: [term_id], references: [term_id])
term_id Int
@@id([generic_article_id, term_id])
}
I tried following this, but it didn't work out as it needs to reference @id, but the generic_article_name is not unique.
Currently I "pretend" for it to be unique and then I find duplicates of the generic_article_name and put the data manually onto the duplicates.Ryan
05/31/2021, 2:31 PMid will be required so you would either need to fetch the id's of all the names you want to create above or just the specific id to create a many-to-many relationship. To connect to the specific record, a unique field is required so there’s no other way around that 🙂Albert Luft
05/31/2021, 2:37 PMgeneric_article_names as unique and then fill out the ones that were duplicated manually hahah, so I guess I'll continue doing thatDaniel Olavio Ferreira
05/31/2021, 6:21 PMAlbert Luft
05/31/2021, 7:11 PMDaniel Olavio Ferreira
05/31/2021, 7:59 PMmodel generic_articles {
generic_article_id Int @id @default(autoincrement())
generic_article_name Int
generic_article_names _generic_article_names_? @relation(fields: [generic_article_namesId], references: [id])
generic_article_namesId Int?
}
model translations {
id Int @id @default(autoincrement())
term_id Int
language_id Int
term String @db.VarChar(60)
generic_article_names _generic_article_names_? @relation(fields: [generic_article_namesId], references: [id])
generic_article_namesId Int?
}
model generic_article_names {
id Int @id @default(autoincrement())
generic_articles _generic_articles_[]
generic_article_id Int
term_id Int
translations _translations_[]
}