Boo
05/07/2022, 3:54 PMauthorId and followingId?
model Users {
id BigInt @id @default(autoincrement())
followers Follows[] @relation("follower")
followings Follows[] @relation("following")
posts Posts[]
createdOn DateTime @default(now()) @map("created_on")
updatedOn DateTime @updatedAt @map("updated_on")
@@map("users")
}
// Following users can have many posts
model Follows {
id BigInt @default(autoincrement())
followerId BigInt @map("follower_id")
followingId BigInt @map("following_id")
follower Users @relation("following", fields: [followerId], references: [id])
following Users @relation("follower", fields: [followingId], references: [id])
followingPosts Posts[]
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @map("updated_at")
@@id([id, followerId, followingId])
@@map("follows")
}
// Posts will always have an authorId
model Posts {
id BigInt @default(autoincrement())
authorId BigInt @map("author_id")
author Users @relation(fields: [authorId], references: [id])
follows Follows @relation(fields: [authorId], references: [followerId])
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @map("updated_at")
@@id([id, authorId])
@@map("bits")
}
// Query should work like this
users.findMany({
where: {
id: 1
},
include: {
followings: { // all posts of the users that I follow
include: {
posts: true
}
}
}
})Nurul
05/09/2022, 1:31 PMmap attribute in the relation fields like this?
// Posts will always have an authorId
model Posts {
id BigInt @default(autoincrement())
authorId BigInt @map("author_id")
author Users @relation(fields: [authorId], references: [id], map: "author")
follows Follows @relation(fields: [authorId], references: [followerId], map: "follows")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @map("updated_at")
@@id([id, authorId])
@@map("bits")
}