ALESSIO
ALESSIO
PPrisma
Created by ALESSIO on 4/24/2025 in #help-and-questions
Relations on non unique fields
Hi guys, i'm building a new db and i need it to be multilingual. in order to achieve that i've created a contents table wich will handle every text/image for each language
model Contents {
id Int
language Languages
content String
content_id Int
type ContentType
challenges_names Challenges[] @relation("challenges_name_content")
challenges_logo Challenges[] @relation("challenges_logo_content")
challenges_badges Challenges[] @relation("challenges_badge_content")
challenges_chapters_name Challenges_Chapters[]

@@id([id])
@@index([content_id])
@@schema("system")
@@unique([content_id, language])
}
model Contents {
id Int
language Languages
content String
content_id Int
type ContentType
challenges_names Challenges[] @relation("challenges_name_content")
challenges_logo Challenges[] @relation("challenges_logo_content")
challenges_badges Challenges[] @relation("challenges_badge_content")
challenges_chapters_name Challenges_Chapters[]

@@id([id])
@@index([content_id])
@@schema("system")
@@unique([content_id, language])
}
Thanks to the content_id column i can join on the needed text and filter by language, that will come from the client basically id content_id language content 1 1 en hello 2 1 it ciao 3 1 es hola Now i can create my challenges modules and have a relation with Contents module like this
model Challenges {
id Int
name_content Contents @relation("challenges_name_content", fields: [name_content_id], references: [content_id])
name_content_id Int
logo_content Contents @relation("challenges_logo_content", fields: [logo_content_id], references: [content_id])
logo_content_id Int
badge_content Contents @relation("challenges_badge_content", fields: [badge_content_id], references: [content_id])
badge_content_id Int
color String
secondary_color String
super_challenge_json Json[]
countries Json[]

chapters Challenges_Chapters[]

@@id([id])

@@schema("system")
}
model Challenges {
id Int
name_content Contents @relation("challenges_name_content", fields: [name_content_id], references: [content_id])
name_content_id Int
logo_content Contents @relation("challenges_logo_content", fields: [logo_content_id], references: [content_id])
logo_content_id Int
badge_content Contents @relation("challenges_badge_content", fields: [badge_content_id], references: [content_id])
badge_content_id Int
color String
secondary_color String
super_challenge_json Json[]
countries Json[]

chapters Challenges_Chapters[]

@@id([id])

@@schema("system")
}
but i get this error Error parsing attribute "@relation": The argument references must refer to a unique criterion in the related model. Consider adding an @unique attribute to the field content_id in the model Contents.Prisma for each relation constraint. How can i deal with this?
6 replies