Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

A small fix that prevents error in PostgreSQL #272

Merged
merged 1 commit into from

2 participants

@panchew

Postgres throws errors when passing :at_least option to the tag_counts_on method; I traced the execution of these methods and noticed the scope of tags_count in the built SQL sentence; all specs are green and my project is happy again.

@artemk artemk merged commit 89fa894 into mbleigh:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 2 additions and 2 deletions.
  1. +2 −2 lib/acts_as_taggable_on/acts_as_taggable_on/collection.rb
View
4 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"
Something went wrong with that request. Please try again.