Skip to content

Instantly share code, notes, and snippets.

@r00k
Created February 21, 2016 04:12
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save r00k/01340add5cba8dee53df to your computer and use it in GitHub Desktop.
Not so hard after all.
def self.popular_this_week
Podcast.
joins(:downloads).
select("podcasts.*, COUNT(podcast_id) as download_count").
where("downloads.created_at >= ?", 1.week.ago.utc).
group("podcasts.id").
order("download_count DESC")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment