I want to build a simple Home Feed like Instagram ...
# orm-help
a
I want to build a simple Home Feed like Instagram where the users sees new posts of the people he follows. So I try to findMany posts where the author of the post is followed by the user who’s requesting. Here is how I imagined it to work:
Copy code
return prisma.post.findMany({  
        where: {
          author: {
            followers: {
              followerId: args.uid
            }
          } 
        }, 
        include: {
          author: { 
            include: {
              followers: {
                where: { 
                  followerId: args.uid
                },
              }
            }
          }
        }
      })
But unfortunately it tells me `"Unknown arg
followers
in where.author.followers for type UserRelationFilter. Available args:",` More in thread
Here are my User and Follows Model: model User {
Copy code
model User {
  uid String @id @default(uuid())
  username String? @db.VarChar(24) @unique 
  followers Follows[] @relation(name: "follower")
  following Follows[] @relation(name: "following")
}

model Follows { 
  follower      User  @relation(name: "follower", fields: [followerId], references: [uid], onUpdate: Cascade, onDelete: Cascade)
  followerId    String 
  following     User @relation(name: "following", fields: [followingId], references: [uid], onUpdate: Cascade, onDelete: Cascade)
  followingId   String  
 
  @@id([followerId, followingId]) 
  @@unique([followerId, followingId])
}
And here the Post model:
Copy code
model Post {
  id             Int     @id @default(autoincrement())
  name           String  @db.VarChar(255) 
  author         User @relation(fields: [authorId], references: [uid], onUpdate: Cascade, onDelete: Cascade)
  authorId String
a
@Aaron Waller User -> followers are one -> many relations So you have to use
some
every
or
none
https://www.prisma.io/docs/concepts/components/prisma-client/crud#get-the-first-record-that-matches-a-specific-criteria
a
@Aarav Shah Hey, I read through the docs but don’t quite get it. Here is my new query:
Copy code
return prisma.post.findMany({   
        where: {
          author: {
            some: {
              followers: { 
                followerId: {
                  equals: args.userId
                 } 
              }
            }
          }
        },
        include: {
          author: {   
            include: {
              followers: {
                include: {
                  follower: true
                }
              }
            }
          }
        }
      })
Unknown arg
some
in where.author.some