semantically-taggable 0.2.2 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/semantically_taggable/tag.rb +14 -0
- data/spec/debug.log +8958 -0
- data/spec/models.rb +4 -0
- data/spec/schema.rb +4 -0
- data/spec/semantically_taggable/tag_parentage_spec.rb +14 -6
- metadata +8 -53
@@ -84,6 +84,20 @@ module SemanticallyTaggable
|
|
84
84
|
existing_tags + created_tags
|
85
85
|
end
|
86
86
|
|
87
|
+
def model_counts
|
88
|
+
SemanticallyTaggable::Tagging.all(
|
89
|
+
:select => 'taggings.taggable_type, COUNT(DISTINCT taggable_id) as model_count',
|
90
|
+
:conditions => %{
|
91
|
+
taggings.tag_id IN
|
92
|
+
(SELECT #{self.id} UNION SELECT child_tag_id from tag_parentages WHERE parent_tag_id = #{self.id})
|
93
|
+
},
|
94
|
+
:group => 'taggings.taggable_type'
|
95
|
+
).inject({}) do |summary_hash, tagging|
|
96
|
+
summary_hash[tagging.taggable_type.to_s] = tagging.model_count.to_i
|
97
|
+
summary_hash
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
87
101
|
def ==(object)
|
88
102
|
super || (object.is_a?(Tag) && name == object.name && scheme == object.scheme)
|
89
103
|
end
|