<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -2159,7 +2159,7 @@ module ActiveRecord
                 klass.send(:type_condition, aliased_table_name)] unless klass.descends_from_active_record?
 
               [through_reflection, reflection].each do |ref|
-                join &lt;&lt; &quot;AND #{interpolate_sql(sanitize_sql(ref.options[:conditions]))} &quot; if ref &amp;&amp; ref.options[:conditions]
+                join &lt;&lt; &quot;AND #{interpolate_sql(sanitize_sql(ref.options[:conditions], aliased_table_name))} &quot; if ref &amp;&amp; ref.options[:conditions]
               end
 
               join</diff>
      <filename>activerecord/lib/active_record/associations.rb</filename>
    </modified>
    <modified>
      <diff>@@ -169,8 +169,8 @@ module ActiveRecord
         end
 
         # Forwards the call to the reflection class.
-        def sanitize_sql(sql)
-          @reflection.klass.send(:sanitize_sql, sql)
+        def sanitize_sql(sql, table_name = @reflection.klass.quoted_table_name)
+          @reflection.klass.send(:sanitize_sql, sql, table_name)
         end
 
         # Assigns the ID of the owner to the corresponding foreign key in +record+.</diff>
      <filename>activerecord/lib/active_record/associations/association_proxy.rb</filename>
    </modified>
    <modified>
      <diff>@@ -2074,12 +2074,12 @@ module ActiveRecord #:nodoc:
         #   [&quot;name='%s' and group_id='%s'&quot;, &quot;foo'bar&quot;, 4]  returns  &quot;name='foo''bar' and group_id='4'&quot;
         #   { :name =&gt; &quot;foo'bar&quot;, :group_id =&gt; 4 }  returns &quot;name='foo''bar' and group_id='4'&quot;
         #   &quot;name='foo''bar' and group_id='4'&quot; returns &quot;name='foo''bar' and group_id='4'&quot;
-        def sanitize_sql_for_conditions(condition)
+        def sanitize_sql_for_conditions(condition, table_name = quoted_table_name)
           return nil if condition.blank?
 
           case condition
             when Array; sanitize_sql_array(condition)
-            when Hash;  sanitize_sql_hash_for_conditions(condition)
+            when Hash;  sanitize_sql_hash_for_conditions(condition, table_name)
             else        condition
           end
         end</diff>
      <filename>activerecord/lib/active_record/base.rb</filename>
    </modified>
    <modified>
      <diff>@@ -29,6 +29,11 @@ class InnerJoinAssociationTest &lt; ActiveRecord::TestCase
     assert_match /INNER JOIN .?categories.? ON.*AND.*.?General.?.*TERMINATING_MARKER/, sql
   end
 
+  def test_construct_finder_sql_applies_aliases_tables_on_association_conditions
+    result = Author.find(:all, :joins =&gt; [:thinking_posts, :welcome_posts])
+    assert_equal authors(:david), result.first
+  end
+
   def test_construct_finder_sql_unpacks_nested_joins
     sql = Author.send(:construct_finder_sql, :joins =&gt; {:posts =&gt; [[:comments]]})
     assert_no_match /inner join.*inner join.*inner join/i, sql, &quot;only two join clauses should be present&quot;</diff>
      <filename>activerecord/test/cases/associations/inner_join_association_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -24,6 +24,8 @@ class Author &lt; ActiveRecord::Base
   has_many :comments_with_order_and_conditions, :through =&gt; :posts, :source =&gt; :comments, :order =&gt; 'comments.body', :conditions =&gt; &quot;comments.body like 'Thank%'&quot;
   has_many :comments_with_include, :through =&gt; :posts, :source =&gt; :comments, :include =&gt; :post
 
+  has_many :thinking_posts, :class_name =&gt; 'Post', :conditions =&gt; { :title =&gt; 'So I was thinking' }
+  has_many :welcome_posts,  :class_name =&gt; 'Post', :conditions =&gt; { :title =&gt; 'Welcome to the weblog' }
 
   has_many :comments_desc, :through =&gt; :posts, :source =&gt; :comments, :order =&gt; 'comments.id DESC'
   has_many :limited_comments, :through =&gt; :posts, :source =&gt; :comments, :limit =&gt; 1</diff>
      <filename>activerecord/test/models/author.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>2dab082d0e1382eb0bc6a143bef6db8deebfd812</id>
    </parent>
  </parents>
  <author>
    <name>Pratik Naik</name>
    <email>pratiknaik@gmail.com</email>
  </author>
  <url>http://github.com/rails/rails/commit/3cb89257b4d7bd706c642e0838909ed13019f557</url>
  <id>3cb89257b4d7bd706c642e0838909ed13019f557</id>
  <committed-date>2009-04-20T05:56:28-07:00</committed-date>
  <authored-date>2009-04-20T05:51:11-07:00</authored-date>
  <message>Ensure JoinAssociation uses aliased table name when multiple associations have hash conditions on the same table</message>
  <tree>bff43f96613ccd6ee2064ecfd2e91a37ab9787ac</tree>
  <committer>
    <name>Pratik Naik</name>
    <email>pratiknaik@gmail.com</email>
  </committer>
</commit>
