Last active
January 9, 2017 18:13
-
-
Save pama/321d09ae6b6fda349eb848114fd796d0 to your computer and use it in GitHub Desktop.
Check box filters
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
scope :category_query, ->(query) do | |
if query.count == 1 | |
joins(:article_categories).where('article_categories.category_id': query.first) | |
else | |
joins(:article_categories). | |
where('article_categories.article_id': ArticleCategory.select('article_categories.article_id') | |
.where(category_id: query) | |
.group('article_categories.article_id') | |
.having("COUNT(article_categories.article_id) > #{query.count - 1}")) | |
.uniq | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment