-
Most popular articles
- {/* {popularArticles?.map((a, i) => {
+ <>
+
+
+
{category?.title}
+
+
+
Most popular articles
+ {/* {popularArticles?.map((a, i) => {
{
return (
@@ -20,9 +23,9 @@ export default function CategoryPage({ category }: { category: CategoryWithInclu
);
}
})} */}
-
+
- {/*
+ {/*
Most recent articles
{recentArticles?.map((a, i) => {
{
@@ -35,22 +38,23 @@ export default function CategoryPage({ category }: { category: CategoryWithInclu
})}
*/}
-
-
All articles
- {category?.articles
- ? Array.from(category?.articles).map((a: Article, i: number) => {
- {
- return (
-
- {a.title}
-
- );
- }
- })
- : ""}
+
+
All articles
+ {category?.articles
+ ? Array.from(category?.articles).map((a: Article, i: number) => {
+ {
+ return (
+
+ {a.title}
+
+ );
+ }
+ })
+ : ""}
+
-
+ >
);
}
export async function getServerSideProps(context: any) {
diff --git a/prisma/migrations/20230207142155_ondelete/migration.sql b/prisma/migrations/20230207142155_ondelete/migration.sql
new file mode 100644
index 0000000..2c3c7ac
--- /dev/null
+++ b/prisma/migrations/20230207142155_ondelete/migration.sql
@@ -0,0 +1,5 @@
+-- DropForeignKey
+ALTER TABLE "Article" DROP CONSTRAINT "Article_categoryId_fkey";
+
+-- AddForeignKey
+ALTER TABLE "Article" ADD CONSTRAINT "Article_categoryId_fkey" FOREIGN KEY ("categoryId") REFERENCES "Category"("id") ON DELETE CASCADE ON UPDATE CASCADE;
diff --git a/prisma/schema.prisma b/prisma/schema.prisma
index 7ff6ce0..6b88e97 100644
--- a/prisma/schema.prisma
+++ b/prisma/schema.prisma
@@ -16,7 +16,7 @@ model Article {
markdown String
contentTable Json?
categoryId String
- category Category @relation(fields: [categoryId], references: [id])
+ category Category @relation(fields: [categoryId], references: [id], onDelete: Cascade)
dateCreated DateTime @default(now())
dateUpdated DateTime @default(now())
}