Three Way Relationship ConnectOrCreate
I have the following mode:
model Bean {
id String @id @default(uuid())
country OriginCountry[]
regions OriginRegion[]
}
model OriginCountry {
id String @id @default(uuid())
beans Bean[]
regions OriginRegion[]
}
model OriginRegion {
id String @id @default(uuid())
parentCountryID String
beans Bean[]
country OriginCountry @relation(fields: [parentCountryID], references: [id])
}
A key scenario is doing a Create of the Bean model, that results in the creation of both a Region and a Country, with a 3 way relationship (A bean connects many to many countries, and many to many regions, a country has many regions and many beans, and a region has many beans and one parent country.
The challenge I'm having is, I can nest a connectorcreate for the country that connectorcreates the regions, but how do I get that region reference back up to the root bean creation?
0 Replies