We are upgrading our app from Mongoose to Prisma with an existing MongoDB schema. The problem is that Prisma does not support relations on fields that are arrays of IDs (String[]), which breaks our attributeFamilies relation in the products model.
Our Prisma schema models relevant to this issue are:
model productattributefamilies {
id String @id @default(auto()) @map("_id") @db.ObjectId
attributes productattributes[]
products products[] @relation(fields: [productIds], references: [id])
productIds String[] @db.ObjectId
// other fields...
}
model products {
id String @id @default(auto()) @map("_id") @db.ObjectId
attributeFamilies productattributefamilies[] @relation(fields: [attributeFamilyIds], references: [id])
attributeFamilyIds String[] @map("attributeFamilies") @db.ObjectId
// other fields...
}
Problem
products.attributeFamilyIds is a String[] of ObjectId references to productattributefamilies.
Prisma does not support relations on array fields, so the declared relation:
attributeFamilies productattributefamilies[] @relation(fields: [attributeFamilyIds], references: [id])
is invalid and Prisma will not load nested attributeFamilies.
Our existing Mongoose app relies on populating this array of IDs, and our API returns nested attributeFamilies with their attributes.
When querying Prisma with .include({ attributeFamilies: { include: { attributes: true } } }),
attributeFamilies is always empty.
This breaks our API response shape, affecting frontend and consumers.
Requirements
We want full backward compatibility with the existing API response, no changes to frontend or API consumers.
We want the Prisma query to return nested attributeFamilies with attributes exactly as before.
We want to avoid any solution that requires flattening or restructuring data in a way that changes the response format.
Ideally, we want a Prisma-friendly way or a script to prepare data to keep compatibility without changing the app frontend or API contract.
Next Steps / Help Needed
Advice on how to model or query this relation in Prisma given the String[] of IDs.
Workarounds to manually load and nest attributeFamilies if Prisma relations don’t support this pattern.
Scripts or migration strategies to make data Prisma-friendly while preserving backward compatibility.
Any alternative approaches to keep the same query results without breaking the API.