【发布时间】:2022-01-27 11:47:54
【问题描述】:
我正在尝试在 Prisma 多对多关系中创建和连接记录,但连接部分不适用于我。
这是我的 Prisma 模型:
model Ingredient {
id Int @id @default(autoincrement())
name String
createdAt DateTime @default(now())
calories Int
protein Int
fat Int
carbs Int
netCarbs Int
metricQuantity Int
metricUnit String
imperialQuantity Int
imperialUnit String
recipes IngredientsOnRecipes[]
categories CategoriesOnIngredients[]
}
model IngredientCategory {
id Int @id @default(autoincrement())
name String
ingredients CategoriesOnIngredients[]
}
model CategoriesOnIngredients {
ingredient Ingredient @relation(fields: [ingredientId], references: [id])
ingredientId Int // relation scalar field (used in the `@relation` attribute above)
ingredientCategory IngredientCategory @relation(fields: [ingredientCategoryId], references: [id])
ingredientCategoryId Int // relation scalar field (used in the `@relation` attribute above)
assignedAt DateTime @default(now())
@@id([ingredientId, ingredientCategoryId])
}
这是我正在运行的 primsa 查询:
const ingredient = await prisma.ingredient.create({
data: {
name: title,
metricQuantity: parseInt(quantityMetric),
metricUnit: unitMetric,
imperialQuantity: parseInt(quantityImperial),
imperialUnit: unitImperial,
calories: parseInt(calories),
netCarbs: parseInt(netCarbs),
carbs: parseInt(carbs),
protein: parseInt(protein),
fat: parseInt(fat),
categories: {
ingredientcategory: {
connect: { id: parseInt(categoryId) },
},
},
},
});
创建一种新成分非常有效,但是当我添加此部分时:
categories: {
ingredientcategory: {
connect: { id: parseInt(categoryId) },
},
},
我收到以下错误:
未知参数 ingredientcategory 在 data.categories.ingredientcategory 中,用于 CategoriesOnIngredientsCreateNestedManyWithoutIngredientInput 类型。你的意思是createMany?可用参数:
类型 CategoriesOnIngredientsCreateNestedManyWithoutIngredientInput {
create?: CategoriesOnIngredientsCreateWithoutIngredientInput |列表 | CategoriesOnIngredientsUncheckedCreateWithoutIngredientInput |列表
connectOrCreate?: CategoriesOnIngredientsCreateOrConnectWithoutIngredientInput |列表
createMany?: CategoriesOnIngredientsCreateManyIngredientInputEnvelope
connect?: CategoriesOnIngredientsWhereUniqueInput |列表
}
【问题讨论】:
标签: prisma