semantically-taggable 0.2.2 → 0.3.1

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.
@@ -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