Last active
June 6, 2020 14:36
-
-
Save nsommer/95256a0354cd69e3f60dc508c15dade6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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