mbleigh-acts-as-taggable-on 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -266,10 +266,12 @@ module ActiveRecord
|
|
266
266
|
|
267
267
|
def related_search_options(context, klass, options = {})
|
268
268
|
tags_to_find = self.tags_on(context).collect { |t| t.name }
|
269
|
+
|
270
|
+
exclude_self = "#{klass.table_name}.id != #{self.id} AND" if self.class == klass
|
269
271
|
|
270
272
|
{ :select => "#{klass.table_name}.*, COUNT(#{Tag.table_name}.id) AS count",
|
271
273
|
:from => "#{klass.table_name}, #{Tag.table_name}, #{Tagging.table_name}",
|
272
|
-
:conditions => ["#{klass.table_name}.id = #{Tagging.table_name}.taggable_id AND #{Tagging.table_name}.taggable_type = '#{klass.to_s}' AND #{Tagging.table_name}.tag_id = #{Tag.table_name}.id AND #{Tag.table_name}.name IN (?)", tags_to_find],
|
274
|
+
:conditions => ["#{exclude_self} #{klass.table_name}.id = #{Tagging.table_name}.taggable_id AND #{Tagging.table_name}.taggable_type = '#{klass.to_s}' AND #{Tagging.table_name}.tag_id = #{Tag.table_name}.id AND #{Tag.table_name}.name IN (?)", tags_to_find],
|
273
275
|
:group => "#{klass.table_name}.id",
|
274
276
|
:order => "count DESC"
|
275
277
|
}.update(options)
|
@@ -9,7 +9,7 @@ module ActiveRecord
|
|
9
9
|
def acts_as_tagger(opts={})
|
10
10
|
has_many :owned_taggings, opts.merge(:as => :tagger, :dependent => :destroy,
|
11
11
|
:include => :tag, :class_name => "Tagging")
|
12
|
-
has_many :owned_tags, :through => :owned_taggings, :source => :tag
|
12
|
+
has_many :owned_tags, :through => :owned_taggings, :source => :tag, :uniq => true
|
13
13
|
include ActiveRecord::Acts::Tagger::InstanceMethods
|
14
14
|
extend ActiveRecord::Acts::Tagger::SingletonMethods
|
15
15
|
end
|
@@ -49,4 +49,4 @@ module ActiveRecord
|
|
49
49
|
|
50
50
|
end
|
51
51
|
end
|
52
|
-
end
|
52
|
+
end
|
@@ -103,6 +103,20 @@ describe "Acts As Taggable On" do
|
|
103
103
|
taggable1.find_related_tags_for(OtherTaggableModel).should include(taggable3)
|
104
104
|
taggable1.find_related_tags_for(OtherTaggableModel).should_not include(taggable2)
|
105
105
|
end
|
106
|
+
|
107
|
+
it "should not include the object itself in the list of related objects" do
|
108
|
+
taggable1 = TaggableModel.create!(:name => "Taggable 1")
|
109
|
+
taggable2 = TaggableModel.create!(:name => "Taggable 2")
|
110
|
+
|
111
|
+
taggable1.tag_list = "one"
|
112
|
+
taggable1.save
|
113
|
+
|
114
|
+
taggable2.tag_list = "one, two"
|
115
|
+
taggable2.save
|
116
|
+
|
117
|
+
taggable1.find_related_tags.should include(taggable2)
|
118
|
+
taggable1.find_related_tags.should_not include(taggable1)
|
119
|
+
end
|
106
120
|
end
|
107
121
|
|
108
122
|
describe 'Tagging Contexts' do
|