Skip to content
This repository has been archived by the owner on Mar 19, 2021. It is now read-only.

Commit

Permalink
Fix mbleigh#544 with any: 'distinct'
Browse files Browse the repository at this point in the history
  • Loading branch information
seuros committed May 24, 2014
1 parent baade08 commit 4aa92a4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions lib/acts_as_taggable_on/taggable/core.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

module ActsAsTaggableOn::Taggable
module Core
def self.included(base)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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(' '))
Expand Down
2 changes: 1 addition & 1 deletion spec/acts_as_taggable_on/taggable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 4aa92a4

Please sign in to comment.