Skip to content

Instantly share code, notes, and snippets.

@mrpunkin
Created February 23, 2012 01:39
Show Gist options
  • Save mrpunkin/1889092 to your computer and use it in GitHub Desktop.
Save mrpunkin/1889092 to your computer and use it in GitHub Desktop.
def self.by_growth(start, stop=Time.now)
votes = Vote.arel_table
select("`photos`.*, COALESCE(SUM(`votes`.value),0.0) AS score_diff")
.joins(:votes)
.where(votes[:created_at].gt(start), votes[:created_at].lt(stop))
.group(votes[:photo_id])
.order("score_diff DESC,score DESC")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment