1 week ago

Thread/Conversation model

Posted 1 week ago by jorgecustodio

Hi! I'm currently trying to implement a feature that allows users to exchange messages about an item (being sold by one of them). I'm having some trouble avoiding the n+1 problem and also finding the correct model. Right now I have:


id ...


id product_id ...


thread_id user_id created_at ....


id thread_id from_id to_id body ...

(1) I want the possibility for one user to delete the thread, leaving the messages there, so the other user can still see them

(2) If later, the user that deleted the thread in (1), decides to send a message regarding the same product he should rejoin the thread but only see the message from that point on. Regarding this feature, I was able to eager load the messages (with) in the Thread model, but have the problem that query cannot be optimized since it has to get the messages only sent after the attach of the current user to that thread.

Has anyone implemented a similar message model? Any ideias that can help?

Thanks!! Jorge

Please sign in or create an account to participate in this conversation.