Howdy. Maybe I'm overthinking this... but lets ass...
# orm-help
d
Howdy. Maybe I'm overthinking this... but lets assume we have something like this:
Copy code
model User {
  id         Int      @id @default(autoincrement())
  createdAt  DateTime @default(now())
  updatedAt  DateTime @updatedAt

  chats Chat[]
}

model Chat {
  id         Int      @id @default(autoincrement())
  createdAt  DateTime @default(now())
  updatedAt  DateTime @updatedAt

  private    Boolean? @default(false)

  users User[]
}
I want to find the chat that includes specific users, but I don't want it including other users and it MUST include all users in my array - like if you want a chat with users
[1,2,3]
(not just
[1,2]
and definitely not
[1,2,3,4]
)... this is the best I got.
Copy code
this.prisma.chat.findFirst({
        where: {
          users: {
            every: {
              OR: [{id: 1}, {id: 2}, {id: 3}]
            }
          }
        }
      })
The problem with the above is that it matches chats for users
[1,2]
... Feels like I might be forced to do a
chat.findMany
and then post-query processing. In an ideal world I'd be able to do something like include the count of users I want and then If I include a count of 3, that that coupled with the every OR clause should sufficiently find me my channel. Is that possible? Thoughts?
I guess a hacky approach is if I know a channel has 3 users, then I can store userCount on the chat in prisma and query that as well... and just keep it up-to-date.
If I do the userCount method, I think my query can also just be...
Copy code
this.prisma.chat.findFirst({
        where: {
          usersCount: 3,
          users: {
            every: {
              id: {
                in: [1, 2, 3]
              }
            }
          }
        }
      })
@Ryan whatchu think
r
I think the
userCount
method seems appropriate