我有以下型号:
model Company {
id String @id @default(uuid())
name String
email String
cocNumber String
taxNumber String?
moneybirdId String? @unique
addresses Address[]
employees Person[]
subscriptions Subscription[]
orders Order[]
}
model Address {
id String @id @default(uuid())
moneybirdId String @unique
primary Boolean
street String
houseNumber Int?
locationName String
extension String?
zipCode String
city String
country Country @relation(fields: [countryId], references: [id])
countryId String
companies Company[]
persons Person[]
}
model Country {
id String @id @default(uuid())
name String
isoCode String
adresses Address[]
}
和以下查询:
let companyInput = {
cocNumber: newCompany.chamber_of_commerce,
email: newCompany.email,
name: newCompany.company_name,
taxNumber: newCompany.tax_number,
moneybirdId: newCompany.id,
addresses: {
connectOrCreate: [
{
create: {
city: newCompany.city,
extension: extension,
houseNumber: parseInt(housenumber),
locationName: "",
primary: true,
zipCode: newCompany.zipcode,
street: street,
country: {connect: {id: country.id}},
moneybirdId: newCompany.id,
},
where: {
moneybirdId: newCompany.id
}
}
]
}
}
导致:原因:“一对多关系'AddressToCountry'上的嵌套连接未找到'Country'记录(需要内联'Address'记录上的关系)。”
country.id 存在且正确。
根据我的经验,一对多不应该存在这个问题,这看起来像是一个多对多错误。这是一个bug吗?
值得一提的是:Create代替connectOrCreate使用相同的connect函数按预期工作
1条答案
按热度按时间x8diyxa71#
发现问题,.next缓存在API路由上检索国家的旧ID。删除.next文件夹并重新编译,不添加缓存