Permalink
Browse files

Fix for incorrect table_names appearing in conditions

Previous to this fix a qualified condition could change the table name
for later conditions

For example if the conditions are

  {'companies_sectors.sectors_id' => 1, :private => false }

Then if the key 'companies_sectors.sectors_id' is processed first then
this will incorrectly set the table_name for the :private key to be
companies_sectors instead of the original value.
  • Loading branch information...
1 parent 991eb1f commit 0056f69e4ca8f529566eb590f4554b7a9b95e37c @mocoso mocoso committed Jun 15, 2009
Showing with 5 additions and 3 deletions.
  1. +5 −3 activerecord/lib/active_record/base.rb
@@ -2303,11 +2303,13 @@ def sanitize_sql_hash_for_conditions(attrs, table_name = quoted_table_name)
# 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

0 comments on commit 0056f69

Please sign in to comment.