Assume I have a Recipe Model, an Ingredient Model, and a many to many mapped as:
model IngredientOnRecipes {
recipe Recipe @relation(fields: [recipeId], references: [id], onDelete: Cascade)
recipeId String
ingredient Ingredient @relation(fields: [ingredientId], references: [id],onDelete: SetNull)
ingredientId String
textDescriptor String
@@id([recipeId,ingredientId])
}
Now I need to populate a Recipe with many Ingredients reference, the second create example in the doc manually populate the 2 category (in my case the Ingredients) in the “create:[]” fields. I have many so I use the map function to create an object in the same form:
const test = ingredients.map(
(ing: { textDescriptor: any; id: any }) =>({
textDescriptor: ing.textDescriptor,
ingredient: {
connect: {
id: ing.id,
},
},
})
)
console.log(test)
prints->
[
{ textDescriptor: '2g', ingredient: { connect: [Object] } },
{ textDescriptor: '5g', ingredient: { connect: [Object] } }
]
Now when i pass this test object in my data as:
const temp = {
data: {
...
ingredients: {
create: test
},
category: recipeBody.category,
},
};
const recipe = await prismaSharedCLient.recipe.create(temp);
a numeric index of each member is added to the list and I got this error
Invalid `prisma.recipe.create()` invocation:
{
data: {
...
ingredients: {
create: {
'0': {
textDescriptor: '2g',
~~~~~~~~~~~~~~
ingredient: {
~~~~~~~~~~
connect: {
id: '13'
}
},
+ id: String,
+ name: String,
? IngredientOnRecipes?: {
? create?: IngredientOnRecipesCreateWithoutIngredientInput | IngredientOnRecipesCreateWithoutIngredientInput | IngredientOnRecipesUncheckedCreateWithoutIngredientInput | IngredientOnRecipesUncheckedCreateWithoutIngredientInput,
? connectOrCreate?: IngredientOnRecipesCreateOrConnectWithoutIngredientInput
| IngredientOnRecipesCreateOrConnectWithoutIngredientInput,
? createMany?: IngredientOnRecipesCreateManyIngredientInputEnvelope,
? connect?: IngredientOnRecipesWhereUniqueInput | IngredientOnRecipesWhereUniqueInput
? }
},
'1': {
textDescriptor: '5g',
...
...
Unknown arg `textDescriptor` in data.ingredients.create.0.textDescriptor for type IngredientCreateWithoutRecipesInput.
What am I doing wrong?