ruby - Rails: Group result set by combination of multiple columns -


i have table called negotiations this

id    seller_id  buyer_id property_id 1        4           190      33123 2        4           190      33123 3        5           191      34000 4        5           191      34000 5        6           200      35000 

i can fetch doing negotiation.all

i want fetch everything, grouped seller_id-buyer_id-property_id combination. in above example want return 3 groups.

is possible in rails application?

you can use enumerable#group_by :

negotiation.all.group_by{|x| [x.seller_id, x.buyer_id, x.property_id]} 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -