From 4aa92a4a6821640a46f3e9849ab41357bd64fbda Mon Sep 17 00:00:00 2001 From: Abdelkader Boudih Date: Sat, 24 May 2014 12:46:14 +0000 Subject: [PATCH] Fix #544 with any: 'distinct' --- lib/acts_as_taggable_on/taggable/core.rb | 10 +++++----- spec/acts_as_taggable_on/taggable_spec.rb | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/acts_as_taggable_on/taggable/core.rb b/lib/acts_as_taggable_on/taggable/core.rb index 91d1c1899..77bee854d 100644 --- a/lib/acts_as_taggable_on/taggable/core.rb +++ b/lib/acts_as_taggable_on/taggable/core.rb @@ -1,4 +1,3 @@ - module ActsAsTaggableOn::Taggable module Core def self.included(base) @@ -117,7 +116,7 @@ def tagged_with(tags, options = {}) " AND #{ActsAsTaggableOn::Tagging.table_name}.tagger_type = #{quote_value(owned_by.class.base_class.to_s, nil)}" end - elsif options.delete(:any) + elsif any = options.delete(:any) # get tags, drop out if nothing returned (we need at least one) tags = if options.delete(:wild) ActsAsTaggableOn::Tag.named_like_any(tag_list) @@ -154,8 +153,10 @@ def tagged_with(tags, options = {}) end joins << tagging_join - group = "#{table_name}.#{primary_key}" - select_clause << group + unless any == 'distinct' # Fix issue #544 + group = "#{table_name}.#{primary_key}" + select_clause << group + end else tags = ActsAsTaggableOn::Tag.named_any(tag_list) @@ -205,7 +206,6 @@ def tagged_with(tags, options = {}) order_by << options[:order] if options[:order].present? - query = self query = self.select(select_clause.join(',')) unless select_clause.empty? query.joins(joins.join(' ')) diff --git a/spec/acts_as_taggable_on/taggable_spec.rb b/spec/acts_as_taggable_on/taggable_spec.rb index f83156b8c..1bec3ccf0 100644 --- a/spec/acts_as_taggable_on/taggable_spec.rb +++ b/spec/acts_as_taggable_on/taggable_spec.rb @@ -212,7 +212,7 @@ @taggable.skill_list = 'ruby' @taggable.save untaggable_model = @taggable.untaggable_models.create!(name:'foobar') - scope_tag = TaggableModel.tagged_with('ruby', :any => 'distinct', order: 'taggable_models.name asc') + scope_tag = TaggableModel.tagged_with('ruby', any: 'distinct', order: 'taggable_models.name asc') expect(UntaggableModel.joins(:taggable_model).merge(scope_tag).except(:select)).to eq([untaggable_model]) end