Skip to content

Instantly share code, notes, and snippets.

@nsommer
Last active June 6, 2020 14:36
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save nsommer/95256a0354cd69e3f60dc508c15dade6 to your computer and use it in GitHub Desktop.
class Article < ApplicationRecord
has_many :comments
has_many :tags
scope :draft, -> { where(published_at: nil) }
scope :published, -> { where.not(published_at: nil) }
scope :commented, -> { joins(:comments).distinct }
end
Article.published.count
# => 12
Article.published.commented.count
# => 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment