I have a Message
model with user_id
and sender_id
attributes following model users message in rails 3 question
I try to query user conversations based on "sender_id"
I did this
has_many :conversations, :class_name => 'Message', select: [:sender_id], group: [:sender_id]
But it only returns the message ID.
Message Load (0.8ms) SELECT sender_id FROM "messages" WHERE "messages"."user_id" = 1 GROUP BY sender_id
=> [#<Message sender_id: 500>]
The select
was used because seems that Postgres requires to explicitly select the attributes to group but If I explicit add them I should be add them in the group clause as well which I don't want.
Any idea how to retrieve messages in a has_many
association grouped by the sender_id
attribute?