Skip to content

Instantly share code, notes, and snippets.

@r00k
Created February 21, 2016 04:12
Show Gist options
  • Save r00k/01340add5cba8dee53df to your computer and use it in GitHub Desktop.
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