I have the following model:
Message.rb: sender_id, receiver_id, created_at
I would like to find all messages where the sender_id and receiver_id are both within an array of ids [1,4,41,543,312,62,234]. I would then like to group all the messages by the pair (sender_id & receiver_id) ordered by created_at.
Is this the right way to write the query? I am looking for an optimal solution here.
Message.where("sender_id IN ? AND receiver_id IN ?", @ids)