From a23ee92d09e2e078616ff4af70b97b2ac2858dbe Mon Sep 17 00:00:00 2001 From: Andrey Eremin Date: Fri, 17 Jan 2014 16:46:07 +0400 Subject: [PATCH] Move Deistinct out of select string. --- CHANGELOG.md | 1 + lib/acts_as_taggable_on/acts_as_taggable_on/core.rb | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 114ebf7c4..9c85fa07e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ As such, a _Feature_ would map to either major or minor. A _bug fix_ to a patch. * [@bzbnhang #440 Did not respect strict_case_match](https://github.com/mbleigh/acts-as-taggable-on/pull/440) * [@znz #456 Fix breaking encoding of tag](https://github.com/mbleigh/acts-as-taggable-on/pull/456) * [@rgould #417 Let '.count' work when tagged_with is accompanied by a group clause](https://github.com/mbleigh/acts-as-taggable-on/pull/417) + * [@developer88 #461 Move 'Distinct' out of select string and use .uniq instead](https://github.com/mbleigh/acts-as-taggable-on/pull/461) * Misc * [@billychan #463 Thread safe support](https://github.com/mbleigh/acts-as-taggable-on/pull/463) * [@billychan #386 Add parse:true instructions to README](https://github.com/mbleigh/acts-as-taggable-on/pull/386) diff --git a/lib/acts_as_taggable_on/acts_as_taggable_on/core.rb b/lib/acts_as_taggable_on/acts_as_taggable_on/core.rb index 1df703af2..ef4046b01 100644 --- a/lib/acts_as_taggable_on/acts_as_taggable_on/core.rb +++ b/lib/acts_as_taggable_on/acts_as_taggable_on/core.rb @@ -141,7 +141,7 @@ def tagged_with(tags, options = {}) # don't need to sanitize sql, map all ids and join with OR logic conditions << tags.map { |t| "#{taggings_alias}.tag_id = #{quote_value(t.id, nil)}" }.join(" OR ") - select_clause = "DISTINCT #{table_name}.*" unless context and tag_types.one? + select_clause = " #{table_name}.*" unless context and tag_types.one? if owned_by tagging_join << " AND " + @@ -200,13 +200,15 @@ def tagged_with(tags, options = {}) order_by << options[:order] if options[:order].present? - select(select_clause). + request = select(select_clause). joins(joins.join(" ")). where(conditions.join(" AND ")). group(group). having(having). order(order_by.join(", ")). readonly(false) + + ((context and tag_types.one?) && options.delete(:any)) ? request : request.uniq end def is_taggable?