Order Conversation based on Chat `createdAt`?
I’m building a chat application using Prisma (PostgreSQL) for my backend, and I need to order conversations by the latest message's createdAt timestamp. However, I’m struggling to find a way to achieve this without adding an additional field like latestMessageCreatedAt to the Conversation model.
Here's my Prisma schema for Conversation and Message:
My Prisma query to fetch conversations:
How can I order conversations by the latest message's createdAt without modifying the schema to add a new field? Is there a way to achieve this in Prisma using a query or aggregation?
0 Replies