Skip to content

Commit

Permalink
Use all column names in GROUP BY for Postgres (Pascal Betz).
Browse files Browse the repository at this point in the history
  • Loading branch information
evan committed Feb 8, 2008
1 parent fbe21ed commit 77d9423
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions generators/tagging/templates/tagging_extensions.rb
Expand Up @@ -125,11 +125,16 @@ def tagged_with(*tag_list)
sql << "AND taggings.taggable_type = '#{ActiveRecord::Base.send(:class_name_of_active_record_descendant, self).to_s}' "
sql << "AND taggings.tag_id = tags.id "

tag_list_condition = tag_list.map {|t| "'#{t}'"}.join(", ")
tag_list_condition = tag_list.map {|name| "'#{name}'"}.join(", ")

sql << "AND (tags.name IN (#{sanitize_sql(tag_list_condition)})) "
sql << "AND #{sanitize_sql(options[:conditions])} " if options[:conditions]
sql << "GROUP BY #{table_name}.id "

columns = column_names.map do |column|
"#{table_name}.#{column}"
end.join(", ")

sql << "GROUP BY #{columns} "
sql << "HAVING COUNT(taggings.tag_id) = #{tag_list.size}"

add_order!(sql, options[:order], scope)
Expand Down

0 comments on commit 77d9423

Please sign in to comment.