<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,5 +1,10 @@
 *Edge*
 
+* Allow conditions on multiple tables to be specified using hash. [Pratik Naik]. Example:
+
+  User.all :joins =&gt; :items, :conditions =&gt; { :age =&gt; 10, :items =&gt; { :color =&gt; 'black' } }
+  Item.first :conditions =&gt; { :items =&gt; { :color =&gt; 'red' } }
+
 * Always treat integer :limit as byte length.  #420 [Tarmo T&#228;nav]
 
 * Partial updates don't update lock_version if nothing changed.  #426 [Daniel Morrison]</diff>
      <filename>activerecord/CHANGELOG</filename>
    </modified>
    <modified>
      <diff>@@ -1999,24 +1999,28 @@ module ActiveRecord #:nodoc:
         #     # =&gt; &quot;age BETWEEN 13 AND 18&quot;
         #   { 'other_records.id' =&gt; 7 }
         #     # =&gt; &quot;`other_records`.`id` = 7&quot;
+        #   { :other_records =&gt; { :id =&gt; 7 } }
+        #     # =&gt; &quot;`other_records`.`id` = 7&quot;
         # And for value objects on a composed_of relationship:
         #   { :address =&gt; Address.new(&quot;123 abc st.&quot;, &quot;chicago&quot;) }
         #     # =&gt; &quot;address_street='123 abc st.' and address_city='chicago'&quot;
-        def sanitize_sql_hash_for_conditions(attrs)
+        def sanitize_sql_hash_for_conditions(attrs, table_name = quoted_table_name)
           attrs = expand_hash_conditions_for_aggregates(attrs)
 
           conditions = attrs.map do |attr, value|
-            attr = attr.to_s
+            unless value.is_a?(Hash)
+              attr = attr.to_s
+
+              # Extract table name from qualified attribute names.
+              if attr.include?('.')
+                table_name, attr = attr.split('.', 2)
+                table_name = connection.quote_table_name(table_name)
+              end
 
-            # Extract table name from qualified attribute names.
-            if attr.include?('.')
-              table_name, attr = attr.split('.', 2)
-              table_name = connection.quote_table_name(table_name)
+              &quot;#{table_name}.#{connection.quote_column_name(attr)} #{attribute_condition(value)}&quot;
             else
-              table_name = quoted_table_name
+              sanitize_sql_hash_for_conditions(value, connection.quote_table_name(attr.to_s))
             end
-
-            &quot;#{table_name}.#{connection.quote_column_name(attr)} #{attribute_condition(value)}&quot;
           end.join(' AND ')
 
           replace_bind_variables(conditions, expand_range_bind_variables(attrs.values))
@@ -2070,6 +2074,8 @@ module ActiveRecord #:nodoc:
           expanded = []
 
           bind_vars.each do |var|
+            next if var.is_a?(Hash)
+
             if var.is_a?(Range)
               expanded &lt;&lt; var.first
               expanded &lt;&lt; var.last</diff>
      <filename>activerecord/lib/active_record/base.rb</filename>
    </modified>
    <modified>
      <diff>@@ -200,6 +200,23 @@ class FinderTest &lt; ActiveRecord::TestCase
     assert_raises(ActiveRecord::RecordNotFound) { Topic.find(1, :conditions =&gt; { 'topics.approved' =&gt; true }) }
   end
 
+  def test_find_on_hash_conditions_with_hashed_table_name
+    assert Topic.find(1, :conditions =&gt; {:topics =&gt; { :approved =&gt; false }})
+    assert_raises(ActiveRecord::RecordNotFound) { Topic.find(1, :conditions =&gt; {:topics =&gt; { :approved =&gt; true }}) }
+  end
+
+  def test_find_with_hash_conditions_on_joined_table
+    firms = Firm.all :joins =&gt; :account, :conditions =&gt; {:accounts =&gt; { :credit_limit =&gt; 50 }}
+    assert_equal 1, firms.size
+    assert_equal companies(:first_firm), firms.first
+  end
+
+  def test_find_with_hash_conditions_on_joined_table_and_with_range
+    firms = DependentFirm.all :joins =&gt; :account, :conditions =&gt; {:name =&gt; 'RailsCore', :accounts =&gt; { :credit_limit =&gt; 55..60 }}
+    assert_equal 1, firms.size
+    assert_equal companies(:rails_core), firms.first
+  end
+
   def test_find_on_hash_conditions_with_explicit_table_name_and_aggregate
     david = customers(:david)
     assert Customer.find(david.id, :conditions =&gt; { 'customers.name' =&gt; david.name, :address =&gt; david.address })</diff>
      <filename>activerecord/test/cases/finder_test.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>582bff71c465075d01b6e062d64b13ac3df4ad56</id>
    </parent>
  </parents>
  <author>
    <name>Pratik Naik</name>
    <login>lifo</login>
    <email>pratiknaik@gmail.com</email>
  </author>
  <url>http://github.com/rails/rails/commit/cd994eff9a343df376bfaec59de5b24a2ab51256</url>
  <id>cd994eff9a343df376bfaec59de5b24a2ab51256</id>
  <committed-date>2008-06-27T17:27:51-07:00</committed-date>
  <authored-date>2008-06-27T17:27:25-07:00</authored-date>
  <message>Allow conditions on multiple tables to be specified using hash.

Examples:

  User.all :joins =&gt; :items, :conditions =&gt; { :age =&gt; 10, :items =&gt; { :color =&gt; 'black' } }
  Item.first :conditions =&gt; { :items =&gt; { :color =&gt; 'red' } }

Note : Hash key in :conditions is referring to the actual table name or the alias defined in query.</message>
  <tree>f18d158c5d11cbba33784a136b0276f8237c6a8b</tree>
  <committer>
    <name>Pratik Naik</name>
    <login>lifo</login>
    <email>pratiknaik@gmail.com</email>
  </committer>
</commit>
