Created
June 24, 2015 17:50
-
-
Save matiasmoya/7d059c6c4118b42e1464 to your computer and use it in GitHub Desktop.
SQL Magic
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
Product | |
has_many reviews | |
... | |
positives = Product.includes(:reviews).select("COUNT(reviews.rating) AS cta").having("cta > 3") | |
... | |
def self.positves | |
includes(:reviews).select("id", "COUNT(reviews.rating) AS cta").having("cta > 3") | |
end | |
... | |
Product.where(:id.nin => positives.pluck(:id)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment