<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -197,7 +197,13 @@ module ActiveRecord
 
           joins = [&quot;LEFT OUTER JOIN #{Tagging.table_name} ON #{Tag.table_name}.id = #{Tagging.table_name}.tag_id&quot;]
           joins &lt;&lt; sanitize_sql([&quot;AND #{Tagging.table_name}.context = ?&quot;,options.delete(:on).to_s]) unless options[:on].nil?
-          joins &lt;&lt; &quot;LEFT OUTER JOIN #{table_name} ON #{table_name}.#{primary_key} = #{Tagging.table_name}.taggable_id&quot;
+          
+          joins &lt;&lt; &quot; INNER JOIN #{table_name} ON #{table_name}.#{primary_key} = #{Tagging.table_name}.taggable_id&quot;
+          unless self.descends_from_active_record?
+            # Current model is STI descendant, so add type checking to the join condition
+            joins &lt;&lt; &quot; AND #{table_name}.#{self.inheritance_column} = '#{self.name}'&quot;
+          end
+          
           joins &lt;&lt; scope[:joins] if scope &amp;&amp; scope[:joins]
 
           at_least  = sanitize_sql(['COUNT(*) &gt;= ?', options.delete(:at_least)]) if options[:at_least]</diff>
      <filename>lib/acts_as_taggable_on/acts_as_taggable_on.rb</filename>
    </modified>
    <modified>
      <diff>@@ -143,5 +143,16 @@ describe &quot;Taggable&quot; do
       InheritingTaggableModel.find_tagged_with(&quot;fork&quot;, :on =&gt; :parts).should be_empty
       AlteredInheritingTaggableModel.find_tagged_with(&quot;fork&quot;, :on =&gt; :parts).first.should == @inherited_different
     end
+    
+    it &quot;should have different tag_counts_on for inherited models&quot; do
+      @inherited_same.tag_list = &quot;bob, kelso&quot;
+      @inherited_same.save!
+      @inherited_different.tag_list = &quot;fork, spoon&quot;
+      @inherited_different.save!
+      
+      InheritingTaggableModel.tag_counts_on(:tags).map(&amp;:name).should == %w(bob kelso)
+      AlteredInheritingTaggableModel.tag_counts_on(:tags).map(&amp;:name).should == %w(fork spoon)
+      TaggableModel.tag_counts_on(:tags).map(&amp;:name).should == %w(bob kelso fork spoon)
+    end
   end
 end</diff>
      <filename>spec/acts_as_taggable_on/taggable_spec.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>eef7d7fcb0680deaa5c0e6c06129d20ae037042e</id>
    </parent>
  </parents>
  <author>
    <name>Georg Ledermann</name>
    <email>ledermann@gmx.de</email>
  </author>
  <url>http://github.com/mbleigh/acts-as-taggable-on/commit/68eedca0a660c46878d522252eb692a5e98fcb53</url>
  <id>68eedca0a660c46878d522252eb692a5e98fcb53</id>
  <committed-date>2009-10-20T08:28:59-07:00</committed-date>
  <authored-date>2009-10-01T01:14:14-07:00</authored-date>
  <message>Fix for tag_counts_on to work with STI</message>
  <tree>a964c6d3982fb1d27a1973e86802d925c637a9e1</tree>
  <committer>
    <name>Michael Bleigh</name>
    <email>michael@intridea.com</email>
  </committer>
</commit>
