Permalink
Browse files

Modify all_tag_counts method to avoid errors in PostgreSQL

  • Loading branch information...
1 parent 1884af8 commit 29dd072810380e0936ae394a40771dd62b9cabda @panchew panchew committed Jul 23, 2012
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 29dd072

Please sign in to comment.