Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@gurgelrenan
Forked from r00k/query.rb
Created November 2, 2016 20:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gurgelrenan/13562024394bf79a9d33a6a31972effa to your computer and use it in GitHub Desktop.
Save gurgelrenan/13562024394bf79a9d33a6a31972effa 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