Chris Bitoy
03/29/2022, 5:56 AMInvalid `prisma.category.create()` invocation:
{
data: {
+ name: String,
? description?: String | null,
? url?: String | null,
subCategories: {
createMany: {
data: {
'0': {
+ name: String,
? description?: String | null,
? url?: String | null,
? image?: String | null,
sub: {
~~~
createMany: {
data: [
{
name: undefined,
description: undefined,
url: undefined,
image: undefined
}
]
}
},
? id?: Int,
? subId?: Int | null,
? createdAt?: DateTime,
? updatedAt?: DateTime
}
}
}
},
? icon?: String | null,
? bgColor?: String | null,
? createdAt?: DateTime,
? updatedAt?: DateTime
}
}
Unknown arg `sub` in data.subCategories.createMany.data.0.sub for type SubcategoryCreateManyCategoryInput. Did you mean `subId`?
Argument name for data.subCategories.createMany.data.0.name is missing.
Argument name for data.name is missing.
Note: Lines with + are required, lines with ? are optional.
Schema:
model Category {
id Int @id @default(autoincrement())
name String @db.VarChar(255)
url String? @db.VarChar(255)
icon String? @db.VarChar(255)
description String? @db.VarChar(255)
bgColor String? @db.VarChar(255)
subCategories Subcategory[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model Subcategory {
id Int @id @default(autoincrement())
name String @db.VarChar(255)
description String?
image String?
url String?
category Category @relation(fields: [categoryId], references: [id])
sub Sub[]
categoryId Int
subId Int?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
Program Program[]
}
model Sub {
id Int @id @default(autoincrement())
name String @db.VarChar(255)
description String?
image String?
url String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
categoryId Int
category Subcategory? @relation(fields: [subcategoryId], references: [id])
subcategoryId Int?
}
create file:
import { PrismaClient } from '@prisma/client';
import { data } from '../../../categoryData';
const ArtData = async (req, res) => {
const prisma = new PrismaClient({ log: ['query'] });
try {
const categoryData = req.body;
await categoryData.map(async (category) => {
const { name, description, url, subCategories } = category;
const {
subName = name,
subDescription = description,
subUrl = url,
image,
sub,
} = subCategories;
const categories = await prisma.category.create({
data: {
name,
description,
url,
subCategories: {
createMany: {
data: [
{
name: subName,
description: subDescription,
url: subUrl,
sub: {
createMany: {
data: [
{
// name: innerName,
},
],
},
},
image,
},
],
},
},
},
});
});
res.status(201).json({ 'category: ': categoryData });
} catch (error) {
console.error(error);
res.status(500);
res.json({ error: 'something went wrong', error });
} finally {
await prisma.$disconnect();
}
};
export default ArtData;
Nurul
03/29/2022, 1:00 PMconst categories = await prisma.category.create({
data: {
name: 'test',
description: 'test',
url: '<https://test.com>',
subCategories: {
create: {
name: 'test',
description: 'test',
url: '<https://test.com>',
sub: {
create: {
name: 'test',
categoryId: 1,
description: 'test',
url: '<https://test.com>',
},
},
},
},
},
});
Chris Bitoy
03/29/2022, 1:45 PM