diff options
author | Vladimir Meremyanin <vladimir@meremyanin.com> | 2009-08-09 23:09:08 +0100 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2009-08-09 23:10:23 +0100 |
commit | 08ec22054f56442b10f67e41c3b7593da6adcabd (patch) | |
tree | c765086fd728e2c8b2fd5c9b80f04d3c2b5f6fb9 | |
parent | 916b18adeb0a1ae09fdaff21dda8d0bc8ed4ffa9 (diff) | |
download | rails-08ec22054f56442b10f67e41c3b7593da6adcabd.tar.gz rails-08ec22054f56442b10f67e41c3b7593da6adcabd.tar.bz2 rails-08ec22054f56442b10f67e41c3b7593da6adcabd.zip |
Make sure association conditions work with :include and :joins [#358 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
-rwxr-xr-x | activerecord/lib/active_record/base.rb | 8 | ||||
-rw-r--r-- | activerecord/test/cases/associations/has_many_associations_test.rb | 6 |
2 files changed, 11 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 3b6e158ab9..d4103b46c0 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -2303,11 +2303,13 @@ module ActiveRecord #:nodoc: # Extract table name from qualified attribute names. if attr.include?('.') - table_name, attr = attr.split('.', 2) - table_name = connection.quote_table_name(table_name) + attr_table_name, attr = attr.split('.', 2) + attr_table_name = connection.quote_table_name(attr_table_name) + else + attr_table_name = table_name end - attribute_condition("#{table_name}.#{connection.quote_column_name(attr)}", value) + attribute_condition("#{attr_table_name}.#{connection.quote_column_name(attr)}", value) else sanitize_sql_hash_for_conditions(value, connection.quote_table_name(attr.to_s)) end diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb index 9345b469ab..b16395776e 100644 --- a/activerecord/test/cases/associations/has_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_associations_test.rb @@ -287,6 +287,12 @@ class HasManyAssociationsTest < ActiveRecord::TestCase assert_equal client2, firm.clients.find(:first, :conditions => ["#{QUOTED_TYPE} = :type", { :type => 'Client' }], :order => "id") end + def test_find_all_with_include_and_conditions + assert_nothing_raised do + Developer.find(:all, :joins => :audit_logs, :conditions => {'audit_logs.message' => nil, :name => 'Smith'}) + end + end + def test_find_in_collection assert_equal Client.find(2).name, companies(:first_firm).clients.find(2).name assert_raise(ActiveRecord::RecordNotFound) { companies(:first_firm).clients.find(6) } |