Created
February 23, 2012 01:39
-
-
Save mrpunkin/1889092 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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