diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2007-10-16 08:08:08 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2007-10-16 08:08:08 +0000 |
commit | f575757ca47f2bbce9866e2a1b1f23b629352b92 (patch) | |
tree | 26a73b0b63a0421aacc2664998e59dc35400732a /activerecord/lib | |
parent | cfbd790ad3dbb9a5b8ee18b4e386abb412246d9e (diff) | |
download | rails-f575757ca47f2bbce9866e2a1b1f23b629352b92.tar.gz rails-f575757ca47f2bbce9866e2a1b1f23b629352b92.tar.bz2 rails-f575757ca47f2bbce9866e2a1b1f23b629352b92.zip |
Qualified column names work in hash conditions, like :conditions => { 'comments.created_at' => ... }. Closes #9733.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7943 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib')
-rwxr-xr-x | activerecord/lib/active_record/base.rb | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 4eb99551cd..47bc8bdb2c 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -1570,9 +1570,21 @@ module ActiveRecord #:nodoc: # # => "status IS NULL and group_id IN (1,2,3)" # { :age => 13..18 } # # => "age BETWEEN 13 AND 18" + # { 'other_records.id' => 7 } + # # => "`other_records`.`id` = 7" def sanitize_sql_hash_for_conditions(attrs) conditions = attrs.map do |attr, value| - "#{quoted_table_name}.#{connection.quote_column_name(attr)} #{attribute_condition(value)}" + 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) + else + table_name = quoted_table_name + end + + "#{table_name}.#{connection.quote_column_name(attr)} #{attribute_condition(value)}" end.join(' AND ') replace_bind_variables(conditions, expand_range_bind_variables(attrs.values)) |