semantically-taggable 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/semantically_taggable/tag.rb +9 -2
- data/spec/debug.log +10796 -0
- data/spec/semantically_taggable/article_tagging_spec.rb +5 -0
- metadata +2 -2
@@ -88,10 +88,17 @@ module SemanticallyTaggable
|
|
88
88
|
# Gets a summary of counts of each model for this tag
|
89
89
|
# e.g. { ''Article' => 20, 'Contact' => 5 }
|
90
90
|
def model_counts
|
91
|
+
joins = nil
|
92
|
+
if scheme.polyhierarchical
|
93
|
+
joins = 'LEFT JOIN tag_parentages ON taggings.tag_id = tag_parentages.child_tag_id'
|
94
|
+
conditions = ['tag_parentages.parent_tag_id = ?', self.id]
|
95
|
+
else
|
96
|
+
conditions = ['taggings.tag_id = ?', self.id]
|
97
|
+
end
|
91
98
|
SemanticallyTaggable::Tagging.all(
|
92
99
|
:select => 'taggings.taggable_type, COUNT(DISTINCT taggings.taggable_id) as model_count',
|
93
|
-
:joins =>
|
94
|
-
:conditions =>
|
100
|
+
:joins => joins,
|
101
|
+
:conditions => conditions,
|
95
102
|
:group => 'taggings.taggable_type'
|
96
103
|
).inject({}) do |summary_hash, tagging|
|
97
104
|
summary_hash[tagging.taggable_type.to_s] = tagging.model_count.to_i
|