Replies: 1 comment 1 reply
-
Hi @akshatg5 👋 Thank you for raising this question. The schema you've provided seems to be a good start for a social media app where users can follow each other. It includes the necessary fields and relations for such functionality. However, there are a few things you might want to consider:
See the modified schema based on the observations above model Follow {
id Int @id @default(autoincrement())
follower User @relation("UserFollowers", fields: [followerId], references: [id])
followerId Int
following User @relation("UsersFollowing", fields: [followingId], references: [id])
followingId Int
createdAt DateTime @default(now())
@@unique([followerId, followingId])
}
model User {
id Int @id @default(autoincrement())
email String @unique
username String @unique
password String
firstName String
lastName String?
bio String?
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
followers Follow[] @relation("UserFollowers")
following Follow[] @relation("UsersFollowing")
posts Post[]
comments Comment[]
upvotes Upvote[]
} |
Beta Was this translation helpful? Give feedback.
-
Question
Hey guys, I've been trying to learn the basics of building a social network app and the follower/following logic has been confusing me. Can anyone experienced and well versed with the topic help me please?
prisma.schema :
Given the schema, I've added the service and controller logic : // socialNetworkService.ts
Can anyone just go though this and confirm if this is the correct approach to do this? Please share if I can do this in a better way also. Thankyouu so much for giving me the time!
How to reproduce (optional)
Expected behavior (optional)
No response
Information about Prisma Schema, Client Queries and Environment (optional)
// Add your schema.prisma
// Add any relevant Prisma Client queries here
OS:
Database:
Node.js version:
Run
prisma -v
to see your Prisma version and paste itBeta Was this translation helpful? Give feedback.
All reactions