sql - Is there a way to use group to select the id's of the grouped records in Rails? -


purchase.all.group( :user_id ).sum( :price ) 

this returns

[{ 1 : 234 }, { 2 : 345 }, ... 

is possible pull purchase ids?

for example, suppose first group returned:

{ user_id : 1, price : 234, ids : [3,6,9] } 

using postgresql, can use array_agg:

purchase.select('user_id, sum(price) price, array_agg(id) ids').group('user_id') 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -