David Ilizarov
06/06/2021, 5:32 AMmodel 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.
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?David Ilizarov
06/06/2021, 5:33 AMDavid Ilizarov
06/06/2021, 5:37 AMthis.prisma.chat.findFirst({
where: {
usersCount: 3,
users: {
every: {
id: {
in: [1, 2, 3]
}
}
}
}
})David Ilizarov
06/06/2021, 5:38 AMRyan
06/07/2021, 8:43 AMuserCount method seems appropriate