Permalink
Browse files

Merge pull request #272 from franciscoguzman/master

A small fix that prevents error in PostgreSQL
  • Loading branch information...
artemk committed Sep 12, 2012
2 parents 1884af8 + 29dd072 commit 89fa894a00297202c0c61dc7f6dfa67135c84327
Showing with 2 additions and 2 deletions.
  1. +2 −2 lib/acts_as_taggable_on/acts_as_taggable_on/collection.rb
@@ -100,8 +100,8 @@ def all_tag_counts(options = {})
tag_conditions.each { |condition| tag_scope = tag_scope.where(condition) }
# GROUP BY and HAVING clauses:
- at_least = sanitize_sql(['tags_count >= ?', options.delete(:at_least)]) if options[:at_least]
- at_most = sanitize_sql(['tags_count <= ?', options.delete(:at_most)]) if options[:at_most]
+ at_least = sanitize_sql(["COUNT(#{ActsAsTaggableOn::Tagging.table_name}.tag_id) >= ?", options.delete(:at_least)]) if options[:at_least]
+ at_most = sanitize_sql(["COUNT(#{ActsAsTaggableOn::Tagging.table_name}.tag_id) <= ?", options.delete(:at_most)]) if options[:at_most]
having = ["COUNT(#{ActsAsTaggableOn::Tagging.table_name}.tag_id) > 0", at_least, at_most].compact.join(' AND ')
group_columns = "#{ActsAsTaggableOn::Tagging.table_name}.tag_id"

0 comments on commit 89fa894

Please sign in to comment.