views:

17

answers:

1

When i write the following code

Post.find(:all,:group=>'comments')

It only gives me the first record with the matching no of comments and skips the other records with the matching no of comments. On the other hand, if i do something like this

Post.count(:all, :group=>'comments')

It gives me

#<OrderedHash {1=>9}>

which means that I have 9 posts which have no of comments = 1 and that is the expected result. Can i do something which gives me a ordered hash but groups of objects with the same no of comments i.e. The posts having equal no of comments are all grouped together and finally i get a hash of group of objects(having similar property).

A: 
Post.find(:all).group_by &:comments
Pär Wieslander
@Pär Wieslander - Thanks. That worked for me.
Silver Spoon