Shadee Merhi
07/19/2022, 2:50 PMConversations
, ConversationParticipants
, and Users
. The relationship between Users
and Conversations
is many-to-many, hence the creation of the ConversationParticipant
model.
Here is my schema:
model User {
id String @id @default(auto()) @map("_id") @db.ObjectId
name String?
email String? @unique
username String @unique
messages Message[]
conversations ConversationParticipants[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model Conversation {
id String @id @default(auto()) @map("_id") @db.ObjectId
participants ConversationParticipants[]
messages Message[] @relation("conversationMessages")
latestMessage Message? @relation(name: "latestConversationMessage", fields: [latestMessageId], references: [id], onUpdate: NoAction, onDelete: NoAction)
latestMessageId String? @unique
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model ConversationParticipants {
id String @id @default(auto()) @map("_id") @db.ObjectId
conversation Conversation @relation(fields: [conversationId], references: [id])
conversationId String
user User @relation(fields: [userId], references: [id])
userId String
}
model Message {
id String @id @default(auto()) @map("_id") @db.ObjectId
conversation Conversation @relation(name: "conversationMessages", fields: [conversationId], references: [id])
conversationId String
isLatestIn Conversation? @relation("latestConversationMessage")
sender User @relation(fields: [senderId], references: [id])
senderId String
body String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
When the user signs in, I am trying to find all of the users conversations (i.e. all of the conversations where there is an existing ConversationParticipant
entity).
My current query is the following:
// the user id comes from the session - working properly
const { id } = session;
const conversations = await prisma.conversation.findMany({
where: {
participants: {
some: {
userId: {
equals: id,
},
},
},
},
include: {
participants: true,
},
});
All of the similar scenarios I can find online are all using the some
operator as well, so I am not sure why this isn’t working. I must be missing something 😅
Any and all help would be greatly appreciated!Austin
07/19/2022, 7:20 PMShadee Merhi
07/19/2022, 8:05 PMAustin
07/20/2022, 10:18 PMsome
to every
, which doesn’t make sense.
The schema + query work as expected on MySQL and SQLite.
Would you mind opening a bug report?Shadee Merhi
07/21/2022, 2:03 PM