samedi 23 mai 2015

ActiveRecord Group by 2 columns

Message model

user_id      # owner of the message 
sender_id    # user that sent message
receiver_id  # user then recieved message 
content      # content of message

I have Messages. I would like to group them by sender_id and receiver_id as these are a "conversation thread".

When I do group I get results that look like

[1,3] => 5   # user 1 and 3 have 5 messages
[1,6] => 2   # user 1 and 6 have 2 messages
[3,1] => 3   # user 3 and 1 have 3 messages

Really [1,3] and [3,1] are part of the same 'group'. How can I achieve this?

Aucun commentaire:

Enregistrer un commentaire