How to get the Sum of a Group of Records?
I am relatively new to rails and also sql. I am using postgres on production.

I have a `Like` model and through polymorphism, it has attributes `likeable_type` and `likeable_id`, this is how items in my `Photo` model are "liked" by the user. I can access a photo through through a like object too as `like.likeable` when the likeable object has `Photo` as the `likeable_type`.

**In short, I want to be able to get a list of Photos that were liked the most in the past 24 hours, with the most liked one on top and the least liked one at the bottom in the order.**

So far I know my code should look something like

    likes = Like.find(:all, :conditions => { :created_at => 1.days.ago.utc...Time.now.utc, :likeable_type => "Photo" })
    likes = likes.group( --- something here --- , SUM( --- something here --- ))

but I am not quite able to figure what the correct syntax shoule be.

any help will be very much appreciated!
How to get the Sum of a Group of Records?
===

I am relatively new to rails and also sql. I am using postgres on production.

I have a `Like` model and through polymorphism, it has attributes `likeable_type` and `likeable_id`, this is how items in my `Photo` model are "liked" by the user. I can access a photo through through a like object too as `like.likeable` when the likeable object has `Photo` as the `likeable_type`.

**In short, I want to be able to get a list of Photos that were liked the most in the past 24 hours, with the most liked one on top and the least liked one at the bottom in the order.**

So far I know my code should look something like

    likes = Like.find(:all, :conditions => { :created_at => 1.days.ago.utc...Time.now.utc, :likeable_type => "Photo" })
    likes = likes.group( --- something here --- , SUM( --- something here --- ))

but I am not quite able to figure what the correct syntax shoule be.

any help will be very much appreciated!