From 4687494b4eb4e37ce85676f30136ca46d30bc68e Mon Sep 17 00:00:00 2001 From: Joel Chippindale Date: Tue, 16 Jun 2009 09:59:11 +0100 Subject: [PATCH] Fix for dot notation in conditions Ensure that dot notation keys in conditions hash don't leak their table_name into subsequent conditions. --- activerecord/lib/active_record/base.rb | 9 +++++---- 1 files changed, 5 insertions(+), 4 deletions(-) diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 97c36a6..1040738 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -2305,18 +2305,19 @@ module ActiveRecord #:nodoc: # # => "address_street='123 abc st.' and address_city='chicago'" 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| 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) + table_name_for_condition, attr = attr.split('.', 2) + table_name_for_condition = connection.quote_table_name(table_name_for_condition) + else + table_name_for_condition = table_name end - attribute_condition("#{table_name}.#{connection.quote_column_name(attr)}", value) + attribute_condition("#{table_name_for_condition}.#{connection.quote_column_name(attr)}", value) else sanitize_sql_hash_for_conditions(value, connection.quote_table_name(attr.to_s)) end -- 1.6.3.1