-
QuestionWe have a few instances where we create nested related models which reference a DB generated UUID and Prisma is able to figure out which field to populate (presumably because we've defined a single relation field). Let's look at a specific example where the IDs are known ahead of time. db.animals.create({
data: {
id: "p",
name: "Panda",
eats: {
createMany: {
data: [
{
animalId: "p",
name: "Bamboo"
}
]
}
}
}
}) Prisma has enough context to infer the This makes sense, but I'm less sure how to handle the case where the outer model ID is generated by the database and the inner model has two references to the outer model. Imagine there's also a model Animal {
// ...
likesFrom Likes[] @relation(...)
likesTo Likes[] @relation(...)
}
model Likes {
fromAnimalId String @db.Uuid
toAnimalId String @db.Uuid
fromAnimal Animal @relation(...)
toAnimal Animal @relation(...)
} If we want to create likes when we create an animal, how can we specify which relation is inferred? db.animals.create({
data: {
name: "Panda",
likes: {
createMany: {
data: [
{
fromAnimalId: "?", // I want this to be inferred
toAnimalId: "f",
}
]
}
}
}
}) Instinctively I'm looking for a way to mark the The only option I can currently see that doesn't involve splitting the query into multiple round trips would be to generate the IDs at the server instead of at the database, but we're using DB generated IDs everywhere else in our application and I'd prefer not to change that precedent. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Apparently I was having a slow day. The relation you use disambiguates. Using |
Beta Was this translation helpful? Give feedback.
Apparently I was having a slow day. The relation you use disambiguates. Using
likesFrom
will infer thetoId
and usinglikesTo
will infer thefromId
. 🤦