Skip to content

Instantly share code, notes, and snippets.

@jfgomez86
Created November 29, 2011 03:21
Show Gist options
  • Select an option

  • Save jfgomez86/1403232 to your computer and use it in GitHub Desktop.

Select an option

Save jfgomez86/1403232 to your computer and use it in GitHub Desktop.
Users who haven't written any post in the past 30 days.
scope :inactive, lambda {
ids = User.joins(:posts)
.select("users.id, max(post.created_at)")
.group("users.id")
.having("max(posts.created_at) < ?", [30.days.ago])
where(id: ids)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment