semantically-taggable 0.4.1 → 0.4.2

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.
@@ -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 => 'LEFT JOIN tag_parentages ON taggings.tag_id = tag_parentages.child_tag_id',
94
- :conditions => %{tag_parentages.parent_tag_id = #{self.id}},
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