I have two models: Message and UserMessage. I got this architecture from somewhere else on SO, but am having some challenges.
Each Message has TWO UserMessage: one UserMessage has a user_id of the sender, and the other has a user_id of the recipient. This allows one party to delete or change the status of the message separate from the other.
How can I find a list of all Messages that were sent between sender_id and receiver_id?
If I do a UserMessage.where(:user_id => sender_id) that doesn't show me just the recipient, for example.
Also: one Message may have many UserMessages, so I need to be able to uniquely find or group by the Message. In other words, five UserMessages all belonging to the same Message I would just want the latest dated UserMessage for that Message.
I am thinking if I can generate a list of all Messages where one UserMessage is sender_id and the other is receiver_id, that would work, but how would I do that?
You are contradicting yourself. At first, you say "Each Message has TWO UserMessage", and then "five UserMessages all belonging to the same Message". If you could rephrase the question to make this understandable it would be easier to help you.